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

Classfile format contains insufficent information for implementing parts of the reflection API

    Details

      Description

      There is an outstanding problem with generic type signatures and type annotations, in that javac doesn't generate either with synthetic/mandated parameters taken into account. At least the latter (type annotations) is an outstanding javac bug.

      This causes an issue that when there are synthetic/mandated parameters, getGenericParameterTypes() returns a *different sized* array depending on whether or not generic information is present. This affects getAnnotatedParameterTypes similarly. The array returned from getParameterTypes() /always/ contains synthetic/mandated parameters.

      The behavior profile is as follows:

      If generic signatures exist in the class file:

      1) getGenericParameterTypes returns an array without synthetic/mandated parameters
      2) getAnnotatedParameterTypes returns an array of AnnotatedTypes without synthetic/mandated parameters, the annotations are on the correct parameter.

      If generic signatures do not exist in the class file:

      1) getGenericParameterTypes returns the same result as getParameterTypes (which contains synthetic/mandated parameters)
      2) getAnnotatedParametertypes returns an array of AnnotatedTypes with synthetic/mandated parameters represented, but the annotations will be on the wrong parameter in some cases (this is due to JDK-8029012)

      A root cause of these problems is that there is no general way to tell whether a given parameter is a formal parameter, or is a synthetic or mandated parameter, and thus there is no general way to map between the formal parameters and the actual parameters.

      This, in turn, makes it extremely difficult to fix issues like JDK-8055063, and makes a perfect fix impossible, because it is not generally possible to know whether a given parameter is synthetic/mandated or not.

      Note: this could be fixed completely by having javac generate generic signatures that also contain information about synthetic and mandated parameters.


      Additionally, some aspects of the reflection API (Parameter.getAnnotatedType()) on a receiver parameter currently cannot be implemented properly.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                emc Eric Mccorkle
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: