lsyf commented on a change in pull request #4379: Fix ehcache: missing interceptor of private constructor and setName method URL: https://github.com/apache/skywalking/pull/4379#discussion_r381049349
########## File path: apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheConstructorInterceptor.java ########## @@ -18,18 +18,28 @@ package org.apache.skywalking.apm.plugin.ehcache.v2; +import net.sf.ehcache.Cache; import net.sf.ehcache.config.CacheConfiguration; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; public class EhcacheConstructorInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - CacheConfiguration cacheConfiguration = (CacheConfiguration) allArguments[0]; + try { + CacheConfiguration cacheConfiguration = (CacheConfiguration) allArguments[0]; - // get cache name - if (cacheConfiguration != null) { - objInst.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(cacheConfiguration.getName())); + // get cache name + if (cacheConfiguration != null) { + objInst.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(cacheConfiguration.getName())); + } + } catch (ClassCastException e) { Review comment: Can I use `instanseof` instead? ```java if (argument instanceof CacheConfiguration) { CacheConfiguration cacheConfiguration = (CacheConfiguration) argument; // get cache name if (cacheConfiguration != null) { objInst.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(cacheConfiguration.getName())); } } else if (argument instanceof Cache) { Cache cache = (Cache) argument; // get cache name if (cache != null && cache.getCacheConfiguration() != null) { objInst.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(cache.getCacheConfiguration().getName())); } } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services