Bug 173376 - [jsr269] Multiple annotations on class, only first is resolved
Summary: [jsr269] Multiple annotations on class, only first is resolved
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-07 19:44 EST by Walter Harley CLA
Modified: 2007-03-21 11:04 EDT (History)
0 users

See Also:


Attachments
Test case (2.37 KB, patch)
2007-02-07 19:44 EST, Walter Harley CLA
no flags Details | Diff
Proposed fix (10.53 KB, patch)
2007-02-07 22:59 EST, Olivier Thomann CLA
no flags Details | Diff
Better patch (8.10 KB, patch)
2007-02-07 23:34 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Harley CLA 2007-02-07 19:44:05 EST
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)
Comment 1 Walter Harley CLA 2007-02-07 19:44:47 EST
Created attachment 58509 [details]
Test case
Comment 2 Olivier Thomann CLA 2007-02-07 22:59:18 EST
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.
Comment 3 Olivier Thomann CLA 2007-02-07 23:34:26 EST
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.
Comment 4 Olivier Thomann CLA 2007-02-08 10:01:07 EST
Fixed and released for 3.3M6.
Added regression test in org.eclipse.jdt.compiler.apt.tests.CompilerAptTests#testTwoAnnotations
Comment 5 Eric Jodet CLA 2007-03-21 11:02:37 EDT
Verified for 3.3 M6 using build I20070320-0010