I hope someone can help me understand what's going wrong (or let me know what additional information I need to provide). I have an aspect where the pointcut seems to be advising code that it shouldn't be advising and it seems to be getting the ok from the isCoerceableFrom method in ReferenceType. I'm using aspectJ 1.6.4 with LTW.
My aspect is defined with:
@Pointcut("(execution (* *.get*()) && this(com.sabre.liberty.user.EPR))")
@Pointcut("(execution (* *.is*()) && this(com.sabre.liberty.user.EPR))")
@Around(value = "monitorEprGetMethod() || monitorEprIsMethod()")
The pointcut should only be applied to instances of "com.sabre.liberty.user.EPR" and its subclasses. Unfortunately it seems
to be getting applied to almost any getter such as:
[TomcatInstrumentableClassLoader@18346a3] weaveinfo Join point 'method-execution(java.util.List com.sabre.liberty.web.RequestTypeRegistry.getRequestTypes())' in Type 'com.sabre.liberty.web.RequestTypeRegistry' (RequestTypeRegistry.java:54) advised by around advice from 'com.sabre.liberty.modules.util.greenbeans.IceDebugAspect' (IceDebugAspect.java) [with runtime test]
[TomcatInstrumentableClassLoader@18346a3] weaveinfo Join point 'method-execution(java.lang.Object com.sabre.liberty.web.RequestTypeRegistry.getDefaultRequestType())' in Type 'com.sabre.liberty.web.RequestTypeRegistry' (RequestTypeRegistry.java:58) advised by around advice from 'com.sabre.liberty.modules.util.greenbeans.IceDebugAspect' (IceDebugAspect.java) [with runtime test]
The class "com.sabre.liberty.web.RequestTypeRegistry" extends Object and implements no interfaces. The interface "com.sabre.liberty.user.EPR"
extends no other interfaces.
It appears that the method ReferenceType.isCoerceableFrom is the one that allows the methods to be advised. The command in the method isCoerceableFrom has the comment "true iff the statement "this = (ThisType) other" would compile" which would never be the case since none of the methods overlap (I guess a subclass could implement the interface and define the methods, but the advice would always be applied to the subclass and never this class). Why would this method decide that one was coerceable to the other? The stacktrace below was while seeing if the advice "@Around(value = "monitorEprGetMethod() || monitorEprIsMethod()")" should be applied to "com.sabre.liberty.web.RequestTypeRegistry.getRequestTypes()". The method returns true.
Thread [main] (Suspended)
ReferenceType.isCoerceableFrom(ResolvedType) line: 298
ExactTypePattern.matchesInstanceof(ResolvedType) line: 177
ExactTypePattern(TypePattern).matches(ResolvedType, TypePattern$MatchKind) line: 150
ThisOrTargetPointcut.matchInternal(Shadow) line: 113
ThisOrTargetPointcut(Pointcut).match(Shadow) line: 146
AndPointcut.matchInternal(Shadow) line: 54
AndPointcut(Pointcut).match(Shadow) line: 146
AndPointcut.matchInternal(Shadow) line: 52
AndPointcut(Pointcut).match(Shadow) line: 146
OrPointcut.matchInternal(Shadow) line: 53
OrPointcut(Pointcut).match(Shadow) line: 146
BcelAdvice(ShadowMunger).match(Shadow, World) line: 79
BcelAdvice(Advice).match(Shadow, World) line: 112
BcelAdvice.match(Shadow, World) line: 145
BcelClassWeaver.match(BcelShadow, List) line: 3025
BcelClassWeaver.match(LazyMethodGen) line: 2499
BcelClassWeaver.weave() line: 480
BcelClassWeaver.weave(BcelWorld, LazyClassGen, List, List, List, boolean) line: 103
BcelWeaver.weave(UnwovenClassFile, BcelObjectType, boolean) line: 1735
BcelWeaver.weaveWithoutDump(UnwovenClassFile, BcelObjectType) line: 1696
BcelWeaver.weaveAndNotify(UnwovenClassFile, BcelObjectType, IWeaveRequestor) line:
1458
BcelWeaver.weave(IClassFileProvider) line: 1272
ClassLoaderWeavingAdaptor(WeavingAdaptor).getWovenBytes(String, byte[]) line: 423
ClassLoaderWeavingAdaptor(WeavingAdaptor).weaveClass(String, byte[], boolean) line: 286
Aj.preProcess(String, byte[], ClassLoader) line: 95
ClassPreProcessorAgentAdapter.transform(ClassLoader, String, Class<?>, ProtectionDomain, byte[]) line: 52
AspectJWeavingEnabler$AspectJClassBypassingClassFileTransformer.transform(ClassLoader, String, Class<?>, ProtectionDomain, byte[]) line: 92
InstrumentationLoadTimeWeaver$FilteringClassFileTransformer.transform(ClassLoader, String, Class<?>, ProtectionDomain, byte[]) line:
181
TransformerManager.transform(ClassLoader, String, Class, ProtectionDomain, byte[]) line: not available
InstrumentationImpl.transform(ClassLoader, String, Class, ProtectionDomain, byte[], boolean) line: not available
ClassLoader.defineClass1(String, byte[], int, int, ProtectionDomain, String) line: not available [native method]
TomcatInstrumentableClassLoader(ClassLoader).defineClass(String, byte[], int, int, ProtectionDomain) line: not available
TomcatInstrumentableClassLoader(SecureClassLoader).defineClass(String, byte[], int, int, CodeSource) line: not available
<snip>