JDK-8274617 : annotations in the super class constructor are not propagated to the anonymous class constructor
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7,8,11,17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2021-10-01
  • Updated: 2022-06-07
  • Resolved: 2022-02-04
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.
JDK 19
19Resolved
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Parameter annotations being copied to inner classes was introduced in JDK-8010737

The behaviour of this cannot be verified using the javap tool.

When running javap on the following example:

@Target(value = {ElementType.PARAMETER}) 
@interface ParamAnnotation {}

public class initParams {
   public initParams(@ParamAnnotation int i) {}

   public void m() {
       new initParams(2) {};
   }
}

Parameter annotations are only visible in the output when using the tool against the parent constructor

Output snippet:
   RuntimeInvisibleParameterAnnotations:
      0:
        0: #12()

When using the tool against the class file generated for the anonymous class, no such Parameter Annotations can be seen in the output

Note: other annotations are not copied either like `constructor` and type annotations
Comments
The JLS does not specify that the implicitly declared constructor of an anonymous class has any annotations, so it is not legal for a Java compiler to put annotations on an anonymous class's constructor. Doing so would be against the language specification
04-02-2022