-
Bug
-
Resolution: Fixed
-
P2
-
6
-
b04
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2158066 | 7 | Eamonn McManus | P2 | Closed | Fixed | b26 |
The JMX source code inadvertently trips over a javac bug (6400189) which leads the compiler to accept code that is not correct. Specifically, in the class com.sun.jmx.mbeanserver.OpenConverter there is the following code:
for (Constructor constr : annotatedConstrList) {
String[] propertyNames =
constr.getAnnotation(propertyNamesClass).value();
...
The method Constructor.getAnnotation is declared like this:
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
This returns T only if it is called on a properly generic variable, such as a Constructor<?> or Constructor<? extends Foo> or Constructor<E>. If it is called on a plain Constructor with no type parameter, then that is a "raw type", and the return type is "erased" to Annotation. So in this case the compiler should consider that constr.getAnnotation(propertyNamesClass) is of type Annotation, and complain that Annotation does not have a value() method.
The fix is trivial: change Constructor to Constructor<?> in the declaration of constr.
A similar problem exists in the method java.beans.MetaData.getAnnotationValue(Constructor), where the parameter type should be changed to Constructor<?>.
This bug was reported by Roman Kennke of aicas GmbH.
for (Constructor constr : annotatedConstrList) {
String[] propertyNames =
constr.getAnnotation(propertyNamesClass).value();
...
The method Constructor.getAnnotation is declared like this:
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
This returns T only if it is called on a properly generic variable, such as a Constructor<?> or Constructor<? extends Foo> or Constructor<E>. If it is called on a plain Constructor with no type parameter, then that is a "raw type", and the return type is "erased" to Annotation. So in this case the compiler should consider that constr.getAnnotation(propertyNamesClass) is of type Annotation, and complain that Annotation does not have a value() method.
The fix is trivial: change Constructor to Constructor<?> in the declaration of constr.
A similar problem exists in the method java.beans.MetaData.getAnnotationValue(Constructor), where the parameter type should be changed to Constructor<?>.
This bug was reported by Roman Kennke of aicas GmbH.
- backported by
-
JDK-2158066 JMX source code includes incorrect Java code
- Closed
- relates to
-
JDK-6746196 Some JMX classes do not compile with Eclipse compiler
- Closed
-
JDK-6400189 raw types and inference
- Closed