Bug 263258 - [1.6][compiler] Code compiles with javac but not the Eclipse compiler
Summary: [1.6][compiler] Code compiles with javac but not the Eclipse compiler
Status: VERIFIED DUPLICATE of bug 167952
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-02 11:52 EST by Olivier Thomann CLA
Modified: 2009-03-10 10:22 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2009-02-02 11:52:27 EST
Compile this test case with the Eclipse compiler:

import java.lang.reflect.*;
import java.beans.*;

public class X {
   void foo() {
       for (Constructor constr : Object.class.getConstructors()) {
           constr.getAnnotation(ConstructorProperties.class).value();
       }
   }
} 

It doesn't compile.
Using HEAD (0.937), we report:
----------
1. WARNING in D:\tests_sources\X.java (at line 6)
	for (Constructor constr : Object.class.getConstructors()) {
	     ^^^^^^^^^^^
Constructor is a raw type. References to generic type Constructor<T> should be parameterized
----------
2. WARNING in D:\tests_sources\X.java (at line 7)
	constr.getAnnotation(ConstructorProperties.class).value();
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor<T> should be parameterized
----------
3. ERROR in D:\tests_sources\X.java (at line 7)
	constr.getAnnotation(ConstructorProperties.class).value();
	                                                  ^^^^^
The method value() is undefined for the type Annotation
----------
3 problems (1 error, 2 warnings)

If we change it for:
import java.lang.reflect.*;
import java.beans.*;

public class X {
   void foo() {
       for (Constructor<?> constr : Object.class.getConstructors()) {
           constr.getAnnotation(ConstructorProperties.class).value();
       }
   }
}

it compiles fine.

Both javac (1.6.0_13 and 1.7_b44) compile it fine. Not even a raw type warning.
It requires 1.6 libraries as java.beans.ConstructorProperties is defined only in 1.6 and above.
Comment 1 Philipe Mulet CLA 2009-02-03 06:39:48 EST
Also note that in source scenario (not using reflect constructor from lib), javac (build 1.7.0-ea-b44) also rejects the code:

import java.lang.annotation.Annotation;
public class X<U> {
	<T extends Annotation> T getAnnotation(Class<T> annotationClass) { return null; }
	void foo(X x) {
		x.getAnnotation(ConstructorProperties.class).value();
	}
}
@interface ConstructorProperties {
	String value();
}

X.java:4: warning: [rawtypes] found raw type: X
missing type parameters for generic class X<U>
        void foo(X x) {
                 ^
X.java:5: warning: [unchecked] unchecked call to <T>getAnnotation(java.lang.Class<T>) as a member of the raw type X
                x.getAnnotation(ConstructorProperties.class).value();
                               ^
X.java:5: cannot find symbol
symbol  : method value()
location: interface java.lang.annotation.Annotation
                x.getAnnotation(ConstructorProperties.class).value();
                                                            ^
1 error
2 warnings
Comment 2 Philipe Mulet CLA 2009-02-03 06:43:21 EST
dup of bug 167952

*** This bug has been marked as a duplicate of bug 167952 ***
Comment 3 Kent Johnson CLA 2009-03-10 10:22:41 EDT
Verified for 3.5M6 using I20090310-0100