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

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


    • Type: CSR
    • Status: Draft
    • Priority: P4
    • Resolution: Unresolved
    • Fix Version/s: tbd_minor
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Compatibility Risk:
    • Compatibility Risk Description:
      Users might expect the method to never return an instance of AnnotatedParameterizedType what is the current behavior.
    • Interface Kind:
      Java API



      A receiver type is currently always represented as a raw type, even if the receiver type is actually parameterized. This makes it impossible to read type annotations of receiver type parameters despite them being present in a class file.


      The reflection API does not currently allow to query all type annotations that are added by javac as it is possible to annotated type variables and the owner type of a parameterized type orthe owner of a nested type. To make this information accessible via the reflection API, it is necessary to change the default behavior of the getAnnotatedReceiverType method to return a parameterized type if appropriate.


      Upon reading a receiver type, it must be checked if the receiver type is parameterized or has an owner class. If so, the receiver type is now represented as an instance of AnnotatedParameterizedType such that it becomes possible to query type annotations of the receiver type's type variables or owner type. This change introduces the possibility of an AnnotatedParameterizedType being returned. The risk of breaking existing code is minimal, since the method currently always returns direct instances of AnnotatedTypeBaseImpl which is an internal type and a super class of the now possible AnnotatedParameterizedTypeImpl.


      On java.lang.reflect.Executable:

       * Returns an {@code AnnotatedType} object that represents the use of a
       * type to specify the receiver type of the method/constructor represented
       * by this {@code Executable} object.
       * The receiver type of a method/constructor is available only if the
       * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code
       * Executable} object <em>represents an instance method or represents a
       * constructor of an inner member class</em>, and the
       * method/constructor <em>either</em> has no receiver parameter or has a
       * receiver parameter with no annotations on its type, then the return
       * value is an {@code AnnotatedType} object representing an element with no
       * annotations.
       * If the receiver type declared type variables or has an owner type, an instance
       * of {@code AnnotatedParameterizedType} will be returned by this method to 
       * give access to any annotations on those variables or the owner type.
       * If this {@code Executable} object represents a static method or
       * represents a constructor of a top level, static member, local, or
       * anonymous class, then the return value is null.
       * @return an object representing the receiver type of the method or
       * constructor represented by this {@code Executable} or {@code null} if
       * this {@code Executable} can not have a receiver parameter
       * @jls 8.4 Method Declarations
       * @jls 8.4.1 Formal Parameters
       * @jls 8.8 Constructor Declarations
      public AnnotatedType getAnnotatedReceiverType() {


          Issue Links



              • Assignee:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: