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

Change Executable.getAnnotatedReceiverType to return an instance of AnnotatedParameterizedType if appropriate



    • CSR
    • Resolution: Approved
    • P4
    • 16
    • core-libs
    • None
    • behavioral
    • minimal
    • This changes the type of the instance returned from Executable::getAnnotatedReceiverType() and Executable::getAnnotatedReceiverType().getType() in most cases. Programs that were written typetesting the returned instances may change behaviour.
    • Java API
    • SE



      Executable::getAnnotatedReceiverType() always returns an AnnotatedType whose underlying Type is a raw type (instance of j.l.Class), even if the type of receiver type is parameterized. This makes it impossible to query the annotations on any type parameters even though they are present in the class file.

      With this change the returned AnnotatedType will always be an AnnotatedParameterizedType, even when there are no type parameters present.

      Note: this has already been pushed. See JDK-8258104 for a follow up.


      Executable::getAnnotatedReceiverType() always returns an AnnotatedType with a raw underlying type. The underlying type is accessed with AnnotatedType::getType() and should model the "un"-annotated type this AnnotatedType is based on. Since this underlying type is always an instance of j.l.Class it is impossible to read type annotations that are present on the receiver type's type parameters despite them being present in a class file.


      The implemented solution is to change the type of the object returned by Executable::getAnnotatedReceiverType() to be an instance of AnnotatedParemeterizedType. This will make sure that calling getType() on the instance will result in an instance of java.lang.reflect.ParameterizedType instead of java.lang.Class.

      With this change programs that were written assuming the return value of Executable::getAnnotatedReceiverType() was always an instance of sun.reflect.annotation.AnnotatedTypeFactory.AnnotatedTypeBaseImpl or that the result of Executable::getAnnotatedReceiverType().getType() is always an instance of j.l.Class must be updated. This is expected to be rare, but a corpus experiment has not been performed. The alternative to implementing this CSR is for the implementation to remain "broken" as there is no other way to attach the extra type state to an instance of j.l.Class, but see also the follow up in JDK-8258104 that in narrows the cases when a ParameterizedType is selected.


        Issue Links



              jfranck Joel Borggrén-Franck (Inactive)
              webbuggrp Webbug Group
              Vicente Arturo Romero Zaldivar
              0 Vote for this issue
              5 Start watching this issue