Summary: | [@AspectJ] NPE on @AJ code with pointcut which contains logical OR operation. | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Eugene Kireyev <eugene_kireyev> | ||||||
Component: | Compiler | Assignee: | aspectj inbox <aspectj-inbox> | ||||||
Status: | RESOLVED FIXED | QA Contact: | |||||||
Severity: | blocker | ||||||||
Priority: | P3 | ||||||||
Version: | 1.5.0 | ||||||||
Target Milestone: | 1.5.1 | ||||||||
Hardware: | PC | ||||||||
OS: | Linux | ||||||||
Whiteboard: | |||||||||
Attachments: |
|
Description
Eugene Kireyev
2006-02-16 11:21:26 EST
For this bug to materialize we require the following: * a pointcut of the form "(pc1 || pc2) && this(Type)" where pc1 includes a wildcard * advice which uses the Type in "this" and also has the extra argument required for use of JoinPoint. i.e.: @Pointcut("(execution(public * Foo.anotherMethod*(..)) || execution(public * Foo.methodA(..))) && this(obj)") protected void methodExec(Object obj){}; @Before("methodExec(obj)") public void beforeMethodExec(JoinPoint thisJoinPoint, Object obj) { System.out.println("Before " + thisJoinPoint.getSignature().toString()); } Created attachment 34907 [details]
patch containing failing testcase
Apply this patch to the tests project.
Created attachment 34908 [details] patch containing proposed fix Apply to the weaver project. When rewritten the pointcut becomes LHS = (execution(public * Foo.anotherMethod*(..)) && this(BindingTypePattern(java.lang.Object,1))) && persingleton(AbstractTracer) RHS = (execution(public * Foo.methodA(..)) && this(BindingTypePattern(java.lang.Object,1))) && persingleton(AbstractTracer) When we come to see if the LHS and RHS could ever match the same join points we return true. If the wildcard isn't there this returns false. Because it's true we then check the name of the binding associated with the LHS with that associated with the RHS. If they're not equal then we add this to the list of ambiguousNames and raise an error. This is where the NPE is coming from because the binding associated with the LHS is null. The reason we're failing here with the @AJ aspect in comment #1 is the addition of the "thisJoinPoint" in the method signature. When we come to validate the bindings we include this extra argument. Consequently, the array of bindings has 2 entries rather than 1. We find the BindingTypePattern(java.lang.Object,1)) and enter this as the second entry in the array of bindings. However, there aren't any others so the first entry in the array of bindings remains null. This causes the NPE when we ask if it's name is the same as the corresponding entry for the RHS (which is also null). I think it's reasonable to add a null check here. If the entry in the LHS array of bindings is null then add the corresponding name to the list of ambiguousNames iff the corresponding entry in the RHS array of bindings isn't null. If they're both null then this is ok. fix committed. fix available |