Community
Participate
Working Groups
The APT annotation discovery visitor walks the AST of a compilation unit, and when it visits an annotation, it makes the following calls: ASTNode.resolveAnnotations( scope, new Annotation[] { annotation }, this.currentBinding); AnnotationBinding binding = annotation.getCompilerAnnotation(); When a class is given two annotations, only the first one seems to be resolved. When the second one gets visited, the AnnotationBinding returned from getCompilerAnnotation() is null. To repro: 0. Ensure you have o.e.jdt.compiler.apt and o.e.jdt.compiler.apt.tests plug-ins in your workspace. 1. Apply the soon-to-be-attached patch file to the o.e.jdt.compiler.apt.tests plug-in, in order to add the new test. 2. Right-click apttestprocessors.jardesc and create the processor jar. 3. Execute CompilerAptTests as a JUnit Test. (Not a JUnit Plug-in Test!) You should see the appended stack trace: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.endVisit(AnnotationDiscoveryVisitor.java:102) at org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation.traverse(MarkerAnnotation.java:39) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1186) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:510) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundEnvImpl.<init>(RoundEnvImpl.java:31) at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:138) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:655) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:373) at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:3024) at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler.call(EclipseCompiler.java:97) at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$4.call(EclipseCompiler.java:335) at org.eclipse.jdt.compiler.apt.tests.CompilerAptTests.compileOneClass(CompilerAptTests.java:341) at org.eclipse.jdt.compiler.apt.tests.CompilerAptTests.testTwoAnnotations(CompilerAptTests.java:204)
Created attachment 58509 [details] Test case
Created attachment 58523 [details] Proposed fix Here is a patch to allow you to make progress. I'll try to revisit it to resolve all annotations at once.
Created attachment 58524 [details] Better patch This patch looks much better. I can pass all existing tests including the attached test case. I like it more than the first one. All annotations for a node are resolved at once. Since there is no need to visit all annotations one by one, this should be fine. Feel free to release it.
Fixed and released for 3.3M6. Added regression test in org.eclipse.jdt.compiler.apt.tests.CompilerAptTests#testTwoAnnotations
Verified for 3.3 M6 using build I20070320-0010