JDK-8058220 : (reflect) no type annotations on a Parameter representing the annotated receiver
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8u20,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2014-09-11
  • Updated: 2018-10-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorUnresolved
Related Reports
Blocks :  
Cloners :  
Relates :  
Relates :  
Description
Executable.getParameters()[0].getAnnotaetdType() has no type annotations for an annotated receiver.

Minimized repro:

----- 8< ------
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.Arrays;

public class IsRecvAParam {

   @Target(ElementType.TYPE_USE)
   @Retention(RetentionPolicy.RUNTIME)
   @interface A {
   }

   class Foo {
      Foo(@A IsRecvAParam IsRecvAParam.this) {
      }
   }

   public static void main(String args[]) {
      Constructor<?> cons = IsRecvAParam.Foo.class.getDeclaredConstructors()[0];

      System.out.println("TypeAnnotations on:");
      System.out.println("getAnnotatedParameterTypes()[0]: " + Arrays.asList(cons.getAnnotatedParameterTypes()[0].getAnnotations()) +
                                   " //correct no type annotation here");
      System.out.println("getAnnotatedReciver(): " + Arrays.asList(cons.getAnnotatedReceiverType().getAnnotations()) + " //correct");

      System.out.println("getParameters()[0].getAnnotatedType(): " + Arrays.asList(cons.getParameters()[0].getAnnotatedType().getAnnotations()) +
                                   " //error");
   }
}
----- 8< ------

Comments
Linked to issue relating to insufficiency of information in current class file format.
05-11-2014

There is no 100% correct solution possible given the current class file format, as there is not any general way to tell whether a given parameter is a receiver parameter or not. Unassigning this from myself, as I cannot make the spec changes that are necessary, and recommending that we open a spec issue related to this one. Also linking to an issue I created about the insufficiency of the current class file format.
05-11-2014

This is a more complicated issue, possibly requiring a spec change. First, javac presently does not properly update the index of type annotations when adding synthetic parameters. Second, there is no general way to determine if a Parameter is a receiver parameter or not.
29-10-2014

I am able to reproduce it. Immediate cause: Parameter.getAnnotatedType() simply calls through to Executable.getAnnotatedParameterTypes().
21-10-2014

Eric, I assume the annotated receiver of an inner class is supposed to show up as a parameter. If that is correct, it is missing type annotations. Please confirm that this is an issue and complete the triage.
11-09-2014

See clone for original report
11-09-2014