Bug 99469 - [1.5][compiler] NPE compiling code with unknown annotations
Summary: [1.5][compiler] NPE compiling code with unknown annotations
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 RC3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-10 16:33 EDT by Olivier Thomann CLA
Modified: 2005-06-16 14:18 EDT (History)
1 user (show)

See Also:


Attachments
Apply on HEAD (1.20 KB, patch)
2005-06-10 16:42 EDT, 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 Olivier Thomann CLA 2005-06-10 16:33:20 EDT
Try to compile this code with 0605-1200.

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Inherited;

@interface ClassAnnotation {
	String value() default "Default";
}

enum EnumClass{
	Value1, Value2, Value3
}

@Retention(RetentionPolicy.RUNTIME)
@Inherited()
@interface ValueAnnotation {
	String value() default "Default";
	boolean booleanValue() default true;
	char charValue() default 'q';
	byte byteValue() default 123;
	short shortValue() default 12345;
	int intValue() default 1234567890;
	float floatValue() default 12345.6789f;
	double doubleValue() default 12345.6789;
	long longValue() default 1234567890123456789l;
	String stringValue() default "stringValue";
	EnumClass enumValue() default EnumClass.Value1;
	Class classValue() default EnumClass.class;
	ClassAnnotation annotationValue() default @ClassAnnotation();
	boolean[] booleanArrayValue() default {true, false};
	char[] charArrayValue() default {'q', 'm'};
	byte[] byteArrayValue() default {123, -123};
	short[] shortArrayValue() default {12345, -12345};
	int[] intArrayValue() default {1234567890, -1234567890};
	float[] floatArrayValue() default {12345.6789f, -12345.6789f};
	double[] doubleArrayValue() default {12345.6789, -12345.6789};
	long[] longArrayValue() default {1234567890123456789l, -1234567890123456789l};
	String[] stringArrayValue() default {"stringValue", "valueString"};
	EnumClass[] enumArrayValue() default {EnumClass.Value1, EnumClass.Value2};
	Class[] classArrayValue() default {X.class, EnumClass.class};
	ClassAnnotation[] annotationArrayValue() default {@ClassAnnotation(),
@ClassAnnotation()};
}

public class X {
	@ValueAnnotation(
		value="ValueAnnotation",
		booleanValue=true,
		charValue='m',
		byteValue=-123,
		shortValue=-12345,
		intValue=-1234567890,
		floatValue=-12345.6789f,
		doubleValue=-12345.6789,
		longValue=-1234567890123456789l,
		stringValue="valueString",
		enumValue=EnumClass.Value3,
		classValue=X.class,
		annotationValue=@ClassAnnotation(value="ClassAnnotation"),
		booleanArrayValue={
			false,
			true
		},
		charArrayValue={
			'm',
			'q'
		},
		byteArrayValue={
			-123,
			123
		},
		shortArrayValue={
			-12345,
			12345
		},
		intArrayValue={
			-1234567890,
			1234567890
		},
		floatArrayValue={
			-12345.6789f,
			12345.6789f
		},
		doubleArrayValue={
			-12345.6789,
			12345.6789
		},
		longArrayValue={
			-1234567890123456789l,
			1234567890123456789l
		},
		stringArrayValue={
			"valueString",
			"stringValue"
		},
		enumArrayValue={
			EnumClass.Value2,
			EnumClass.Value1
		},
		classArrayValue={
			EnumClass.class,
			X.class
		},
		annotationArrayValue={
			@ClassAnnotation(value="ClassAnnotation1"),
			@ClassAnnotation(value="ClassAnnotation2")
		})
	public String field;
	@ValueAnnotation(value="ValueAnnotation",booleanValue=true,charValue='m',byteValue=-123,shortValue=-12345,
		
intValue=-1234567890,floatValue=-12345.6789f,doubleValue=-12345.6789,longValue=-1234567890123456789l,
		
stringValue="valueString",enumValue=EnumClass.Value3,classValue=AnnotationTestClass.class,
		
annotationValue=@ClassAnnotation(value="ClassAnnotation"),booleanArrayValue={false,true},charArrayValue={'m','q'},
		
byteArrayValue={-123,123},shortArrayValue={-12345,12345},intArrayValue={-1234567890,1234567890},
		
floatArrayValue={-12345.6789f,12345.6789f},doubleArrayValue={-12345.6789,12345.6789},
		
longArrayValue={-1234567890123456789l,1234567890123456789l},stringArrayValue={"valueString",
"stringValue"},
		
enumArrayValue={EnumClass.Value2,EnumClass.Value1},classArrayValue={EnumClass.class,
AnnotationTestClass.class},
			annotationArrayValue={@ClassAnnotation(value="ClassAnnotation1"),
@ClassAnnotation(value="ClassAnnotation2")})
	@ConstructorAnnotation(value="ConstructorAnnotation")
	public AnnotationTestClass(@ParameterAnnotation(value="ParameterAnnotation")
@Deprecated() String param1, @ParameterAnnotation(value="ParameterAnnotation")
String param2) {
	}
	@ValueAnnotation(value="ValueAnnotation",booleanValue=true,charValue='m',byteValue=-123,shortValue=-12345,
		
intValue=-1234567890,floatValue=-12345.6789f,doubleValue=-12345.6789,longValue=-1234567890123456789l,
		
stringValue="valueString",enumValue=EnumClass.Value3,classValue=AnnotationTestClass.class,
		
annotationValue=@ClassAnnotation(value="ClassAnnotation"),booleanArrayValue={false,true},charArrayValue={'m','q'},
		
byteArrayValue={-123,123},shortArrayValue={-12345,12345},intArrayValue={-1234567890,1234567890},
		
floatArrayValue={-12345.6789f,12345.6789f},doubleArrayValue={-12345.6789,12345.6789},
		
longArrayValue={-1234567890123456789l,1234567890123456789l},stringArrayValue={"valueString",
"stringValue"},
		
enumArrayValue={EnumClass.Value2,EnumClass.Value1},classArrayValue={EnumClass.class,
AnnotationTestClass.class},
			annotationArrayValue={@ClassAnnotation(value="ClassAnnotation1"),
@ClassAnnotation(value="ClassAnnotation2")})
	@MethodAnnotation(value="MethodAnnotation")
	public void method(@ParameterAnnotation(value="ParameterAnnotation")
@Deprecated() String param1, @ParameterAnnotation(value="ParameterAnnotation")
String param2){
	}
}

You get:
----------
1. ERROR in d:\tests_sources\X.java
 (at line 0)
	import java.lang.annotation.Retention;
	^
Internal compiler error
java.lang.NullPointerException
	at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.bindArguments(AbstractMethodDeclaration.java:90)
	at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:389)
	at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1063)
	at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1112)
	at
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:305)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:504)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
	at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:2691)
	at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1151)
	at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1048)
	at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1040)
	at org.eclipse.jdt.core.tools.compiler.Compile.main(Compile.java:19)

----------
2. ERROR in d:\tests_sources\X.java
 (at line 109)
	stringValue="valueString",enumValue=EnumClass.Value3,classValue=AnnotationTestClass.class,
	                                                                ^^^^^^^^^^^^^^^^^^^
AnnotationTestClass cannot be resolved to a type
----------
3. ERROR in d:\tests_sources\X.java
 (at line 114)
	enumArrayValue={EnumClass.Value2,EnumClass.Value1},classArrayValue={EnumClass.class,
AnnotationTestClass.class},
	                                                                              
      ^^^^^^^^^^^^^^^^^^^
AnnotationTestClass cannot be resolved to a type
----------
4. ERROR in d:\tests_sources\X.java
 (at line 116)
	@ConstructorAnnotation(value="ConstructorAnnotation")
	 ^^^^^^^^^^^^^^^^^^^^^
ConstructorAnnotation cannot be resolved to a type
----------
5. ERROR in d:\tests_sources\X.java
 (at line 117)
	public AnnotationTestClass(@ParameterAnnotation(value="ParameterAnnotation")
@Deprecated() String param1, @ParameterAnnotation(value="ParameterAnnotation")
String param2) {
	      
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Return type for the method is missing
----------
6. ERROR in d:\tests_sources\X.java
 (at line 117)
	public AnnotationTestClass(@ParameterAnnotation(value="ParameterAnnotation")
@Deprecated() String param1, @ParameterAnnotation(value="ParameterAnnotation")
String param2) {
	                            ^^^^^^^^^^^^^^^^^^^
ParameterAnnotation cannot be resolved to a type
----------
7. ERROR in d:\tests_sources\X.java
 (at line 121)
	stringValue="valueString",enumValue=EnumClass.Value3,classValue=AnnotationTestClass.class,
	                                                                ^^^^^^^^^^^^^^^^^^^
AnnotationTestClass cannot be resolved to a type
----------
8. ERROR in d:\tests_sources\X.java
 (at line 126)
	enumArrayValue={EnumClass.Value2,EnumClass.Value1},classArrayValue={EnumClass.class,
AnnotationTestClass.class},
	                                                                              
      ^^^^^^^^^^^^^^^^^^^
AnnotationTestClass cannot be resolved to a type
----------
9. ERROR in d:\tests_sources\X.java
 (at line 128)
	@MethodAnnotation(value="MethodAnnotation")
	 ^^^^^^^^^^^^^^^^
MethodAnnotation cannot be resolved to a type
----------
Comment 1 Olivier Thomann CLA 2005-06-10 16:41:54 EDT
Smaller test case:

public class X {

	public foo(@Deprecated() String s) {
	}
}

You need a method for which the binding is null and a parameter annotation.
Comment 2 Olivier Thomann CLA 2005-06-10 16:42:53 EDT
Created attachment 22839 [details]
Apply on HEAD

With this patch, the error is:
----------
1. ERROR in d:\tests_sources\X.java
 (at line 3)
	public foo(@Deprecated() String s) {
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Return type for the method is missing
----------
1 problem (1 error)
Comment 3 Philipe Mulet CLA 2005-06-13 06:42:03 EDT
+1 for RC3.

Dani - pls cast a vote for it. You know how exceptions in compiler can damage
the editing experience... <g>
Comment 4 Dani Megert CLA 2005-06-13 06:44:01 EDT
+1 for 3.1 RC3.
Comment 5 Philipe Mulet CLA 2005-06-13 09:56:46 EDT
Added AnnotationTest#test167.

Made similar fix to proposed, but extracted the null check out of the loop to
avoid penalizing standard scenario.

Fixed
Comment 6 Olivier Thomann CLA 2005-06-16 14:18:28 EDT
Verified using N20050616-0010 + JDT/Core HEAD