Why are there errors in released Java source code?
I downloaded JDK source code (6u23 build b5) for research, and Eclipsed decid开发者_JS百科ed to automatically build it. Astonishingly, it found errors.
A few examples.
java.beans.MetaData, line 1365:
ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
Type mismatch: cannot convert from Annotation to ConstructorProperties
java.awt.AWTEvent, line 220:
AWTAccessor.setAWTEventAccessor(new AWTAccessor.AWTEventAccessor() {
The type new AWTAccessor.AWTEventAccessor(){} must implement the inherited abstract method AWTAccessor.AWTEventAccessor.getAccessControlContext(AWTEvent)
I thought this code supposed to be absolutely correct, if not being one of the best examples of Java usage that one can learn from. But that doesn't even compile!
Update: I exported java package into individual project, removed the java package default import to avoid possible namespace conflicts and used JVM 1.6.0 to build it.
The problem you have here is that the specification for generics has evolved over time. :| The latest version of Sun/Oracle Java compiles this code correctly, however its the IDE which doesn't realise it now compiles. (Unfortunately Eclipse uses its own compiler and its not always exactly the same as the Sun/Oracle compiler)
I am pretty sure older versions of the compiler would produce an error for this line of code.
It used to be that if a type was not a generic, all generics were turned off, even if that didn't make sense. In the case of this method.
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
// constructor is not a generic type.
private static String[] getAnnotationValue(Constructor constructor) {
ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
The older compilers would assume this was a non-generic method as the Constructor is not generic. However the newer compiler identifies this method is self contained and it shouldn't matter whether the class is a generic type of not.
Oh there is an awful lot of confusion about the implementation of the JLS as far as generic method parameters are concerned. It might well be that the code you posted compiles with javac, but not with Eclipse (which in my opinion has a superior but incorrect compiler). This compiles in Eclipse:
private static String[] getAnnotationValue(Constructor<?> constructor) {
ConstructorProperties annotation =
constructor.getAnnotation(ConstructorProperties.class);
This doesn't (your example, with a raw-typed Constructor):
private static String[] getAnnotationValue(Constructor constructor) {
ConstructorProperties annotation =
constructor.getAnnotation(ConstructorProperties.class);
Check out this question I had recently. It gives me the creeps:
Reference is ambiguous with generics
I'd definitely look for the error in Eclipse
精彩评论