Community
Participate
Working Groups
Encountered during a JavaPolis demo. I was using a pre-release development version. However, reproducable with latest post-release development version as well. Create the following source file: package banking; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; public class Main { public static void main(String[] args) { System.out.println("Main"); } } @Aspect class MainLogger { @Pointcut("execution(* main(..))") public void log(JoinPoint thisJoinPoint) { System.out.println("Before " thisJoinPoint"); } } Note that the import statement for JoinPoint is lacking. Compiling this source file crahses the compiler. Adding import statement for JoinPoint makes it work fine. C:\work\aop\src\workspace\CallDebugBug>ajc -version AspectJ Compiler DEVELOPMENT built on Tuesday Dec 20, 2005 at 13:58:29 GMT C:\work\aop\src\workspace\CallDebugBug>ajc -1.5 banking\Main.java C:\work\aop\src\workspace\CallDebugBug\banking\Main.java [error] Internal compil er error java.lang.NullPointerException at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.buildFormalAdviceBindingsFrom(ValidateAtAspectJAnnotationsVisitor.java:417 ) at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.convertToPointcutDeclaration(ValidateAtAspectJAnnotationsVisitor.java:513) at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.visit(ValidateAtAspectJAnnotationsVisitor.java:188) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.t raverse(MethodDeclaration.java:185) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.tra verse(TypeDeclaration.java:1195) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDecl aration.traverse(CompilationUnitDeclaration.java:339) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.beforeAnalysing( AjCompilerAdapter.java:154) at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$before$org_asp ectj_ajdt_internal_compiler_CompilerAdapter$7$db78446d(CompilerAdapter.aj:101) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compil er.java:517) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compil er.java:329) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilat ion(AjBuildManager.java:811) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuild Manager.java:230) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBu ildManager.java:156) at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112) at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60) at org.aspectj.tools.ajc.Main.run(Main.java:326) at org.aspectj.tools.ajc.Main.runMain(Main.java:240) at org.aspectj.tools.ajc.Main.main(Main.java:83) (no source information available) C:\work\aop\src\workspace\CallDebugBug\banking\Main.java:16 [error] JoinPoint ca nnot be resolved to a type public void log(JoinPoint thisJoinPoint) { ^^^^^^^ C:\work\aop\src\workspace\CallDebugBug\banking\Main.java:17 [error] Syntax error , insert ")" to complete MethodInvocation System.out.println("Before " thisJoinPoint"); C:\work\aop\src\workspace\CallDebugBug\banking\Main.java:17 [error] Syntax error , insert ";" to complete BlockStatements System.out.println("Before " thisJoinPoint"); ABORT Exception thrown from AspectJ DEVELOPMENT This might be logged as a bug already -- find current bugs at http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Compiler Bugs for exceptions thrown have titles File:line from the top stack, e.g., "SomeFile.java:243" If you don't find the exception below in a bug, please add a new bug at http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ To make the bug a priority, please include a test program that can reproduce this exception. when validating @AspectJ annotations log when analysing types defined in compilation unit C:\work\aop\src\workspace\CallD ebugBug\banking\Main.java when processing compilation unit C:\work\aop\src\workspace\CallDebugBug\banking\ Main.java when batch building with classpath: c:\java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;c: \java\jdk1.5.0_04\jre\lib\ext\localedata.jar;c:\java\jdk1.5.0_04\jre\lib\ext\sun jce_provider.jar;c:\java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar;c:\java\jdk1.5.0_ 04\lib\tools.jar;c:\java\jdk1.5.0_04\jre\lib\rt.jar;C:\java\aspectj\aspectj5\lib \aspectjrt.jar;C:\java\log4j\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;C:\jav a\jess\Jess61p5\jess.jar;c:\java\j2sdkee1.3.1\lib\system\cloudscape.jar;c:\java\ j2sdkee1.3.1\lib\system\tools.jar;c:\java\j2sdkee1.3.1\lib\cloudscape\RmiJdbc.ja r;c:\java\j2sdkee1.3.1\lib\cloudscape\cloudclient.jar;c:\java\j2sdkee1.3.1\lib\c lasses;c:\java\j2sdkee1.3.1\classes;c:\java\j2sdkee1.3.1\lib\j2ee.jar;c:\java\j2 sdkee1.3.1\lib\toolclasses;c:\java\j2sdkee1.3.1\lib\j2eetools.jar;c:\java\j2sdke e1.3.1\lib\locale;c:\java\j2sdkee1.3.1\lib\j2ee.jar;c:\java\j2sdkee1.3.1\lib\jha ll.jar;c:\java\j2sdkee1.3.1\lib\locale;c:\java\jdk1.5.0_04\lib\tools.jar;c:\java \j2sdkee1.3.1\lib\jhall.jar;C:\java\ws\axis\axis-1_1\lib\axis.jar;C:\java\ws\axi s\axis-1_1\lib\axis-ant.jar;C:\java\ws\axis\axis-1_1\lib\commons-discovery.jar;C :\java\ws\axis\axis-1_1\lib\commons-logging.jar;C:\java\ws\axis\axis-1_1\lib\jax rpc.jar;C:\java\ws\axis\axis-1_1\lib\saaj.jar;C:\java\ws\axis\axis-1_1\lib\log4j -1.2.8.jar;C:\java\ws\axis\axis-1_1\lib\wsdl4j.jar;C:\java\concurrency\concurren cy.jar;C:\java\junit\junit3.8.1\junit.jar;.; null java.lang.NullPointerException at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.buildFormalAdviceBindingsFrom(ValidateAtAspectJAnnotationsVisitor.java:417 ) at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.convertToPointcutDeclaration(ValidateAtAspectJAnnotationsVisitor.java:513) at org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVi sitor.visit(ValidateAtAspectJAnnotationsVisitor.java:188) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.t raverse(MethodDeclaration.java:185) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.tra verse(TypeDeclaration.java:1195) at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDecl aration.traverse(CompilationUnitDeclaration.java:339) at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.beforeAnalysing( AjCompilerAdapter.java:154) at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$before$org_asp ectj_ajdt_internal_compiler_CompilerAdapter$7$db78446d(CompilerAdapter.aj:101) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compil er.java:517) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compil er.java:329) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilat ion(AjBuildManager.java:811) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuild Manager.java:230) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBu ildManager.java:156) at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112) at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60) at org.aspectj.tools.ajc.Main.run(Main.java:326) at org.aspectj.tools.ajc.Main.runMain(Main.java:240) at org.aspectj.tools.ajc.Main.main(Main.java:83) 1 fail|abort, 4 errors
That's one for me...
Created attachment 34833 [details] zip containing test and fix patches The attached zip file contains two patches: * pr121616-org-aspectj-ajdt-core-patch.txt - apply to the org.aspectj.ajdt.core project - contains the proposed fix * pr121616-tests-patch.txt - apply to the tests project - contains the testcase The problem is occuring when the only error is the lack of import for JoinPoint. In this case there are no errors marked against any other types and we visit the MethodDeclaration's using a ValidateAtAspectJAnnotationsVisitor. When we come to the MethodDeclaration corresponding to public @Before("execution(* main(..))") void log(JoinPoint thisJoinPoint) { } we go ahead without checking first whether there are any errors marked against it and then blow up with the NPE. In the case of there not being an import for @Aspect as well as JoinPoint, we don't get this far because the traverse() method in TypeDeclaration has a check first to see if there's an error reported against the typedeclaration (which there is because the import of @Aspect is missing) and if there is it just returns (and hence no NPE). In the case of there just being no import for @Before then everything is ok because no adviceAnnotations or pointcutAnnotations have been added and so we don't enter the code which is causing the NPE. Therefore the proposed fix is to add a check for errors at the start of the ValidateAtAspectJAnnotationsVisitor.visit(MethodDeclaration, ClassScope). If there are errors, then just return false.
fix checked in.
Closing this bug as fixed as the patch has been integrated into AspectJ. Moreover, AJDT 1.3.1.20060309111525 for Eclipse 3.1 includes an AspectJ which contains this fix and the next build of AJDT for Eclipse 3.2M5 will also contain the fix.