Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6643627

JMX source code includes incorrect Java code

XMLWordPrintable

    • b04
    • generic
    • generic

        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.

              emcmanus Eamonn McManus
              emcmanus Eamonn McManus
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: