Bug 84764

Summary: NullPointerException with Annotations
Product: [Eclipse Project] JDT Reporter: Bill Back <bill>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Bill Back CLA 2005-02-09 05:49:16 EST
It appears that if the parameters in an annotation are not listed by name in the order they were declared 
an exception is thrown.  See the "switchedOrderAnnotation" method below.  If I switch the parameters 
back into the order that they were declared in the annotation interface, the error stops occurring.  As 
far as I can tell, there is no rule that says the annotation parameters have to be in order since they are 
listed by name and you can provide defaults.  Additional info:  I'm running 3.1M4 on OS X.4 with Java 
1.5.0.

ExampleAnnotation.java:

import java.lang.annotation.*;

@Retention (RetentionPolicy.RUNTIME)
public @interface ExampleAnnotation {
  String name() default "Example";
  int number();
}

AnnotatedClass.java:

import java.lang.annotation.*;

public class AnnotatedClass {

  @Deprecated
  public void oldMethod () {}

  @ExampleAnnotation (number = 1)
  public void simpleAnnotated() {}

  @ExampleAnnotation (name="Example 2", number = 2)
  public void namedAnnotated() {}

  @ExampleAnnotation (number = 3, name="Example 3")
  public void switchedOrderAnnotated() {}

  public static void main(String[] args) {

  }
}

Error Info:

Error 2005-02-09 05:23:49.361 An internal error occurred during: "Java AST creation".
java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:204)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:398)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve
(AbstractMethodDeclaration.java:388)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1014)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1063)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve
(CompilationUnitDeclaration.java:280)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:651)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:443)
at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:708)
at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:574)
at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:563)
at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:494)
at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager
$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:165)
at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run
(SelectionListenerWithASTManager.java:142)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
Comment 1 Philipe Mulet CLA 2005-02-09 05:57:30 EST
Dup

*** This bug has been marked as a duplicate of 81825 ***
Comment 2 Philipe Mulet CLA 2005-02-09 05:58:32 EST
Fix got released after 3.1M4. Any integration build since M4 would contain it.