JDK-8138612 : Do not retain declaration annotations on lambda formal parameters
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u60
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-09-30
  • Updated: 2016-01-06
  • Resolved: 2015-11-06
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 9
9 b93Fixed
Related Reports
Duplicate :  
Relates :  
Sub Tasks
JDK-8140279 :  
Description
In JDK 8u40, javac dropped declaration annotations on lambda formals on the floor. Nothing in JLS8 suggested this treatment for such annotations, but it was a happy accident nonetheless -- according to Brian Goetz, there is no need to tie the synthetic method generated for a lambda expression back to the source lambda expression by carefully mapping the parameter annotations.

in JDK 9 (and presumably in JDK 8u60), javac preserves declaration annotations on lambda formals as Runtime[In]VisibleParameterAnnotations in the synthetic method. Similar to the names of the lambda formals, this preservation should not happen. The covering JLS change is specified in JDK-8140279.
Comments
See comment about the failing/ignored test tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java made in https://bugs.openjdk.java.net/browse/JDK-8079060 As a part of closing the present ticket, this test issue should be looked into and cleaned up.
22-10-2015

I don't think the assertion "javac already drops declaration annotations on lambda formals on the floor" is quite correct. In com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzerPreprocessor.LambdaTranslationContext#translate(com.sun.tools.javac.code.Symbol, com.sun.tools.javac.comp.LambdaToMethod.LambdaSymbolKind) I see: (circa line 1933) if (ret != sym) { ret.setDeclarationAttributes(sym.getRawAttributes()); ret.setTypeAttributes(sym.getRawTypeAttributes()); } Also compiling this program with 9b85: @interface Annot { } interface Runnable { void run(int x); } public class X { static final long LM = 1L << 40; void run(Runnable r) { r.run(10); } public static void main(@Annot String [] args) { new X().run((@Annot int x) -> { System.out.println(x + args.length); }); } } I see the lambda method having parameter annotations: private static void lambda$main$0(java.lang.String[], int); descriptor: ([Ljava/lang/String;I)V flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC Code: stack=3, locals=2, args_size=2 0: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 3: iload_1 4: aload_0 5: arraylength 6: iadd 7: invokevirtual #8 // Method java/io/PrintStream.println:(I)V 10: return LineNumberTable: line 15: 0 RuntimeInvisibleParameterAnnotations: 0: 0: #24() 1: 0: #24() } May I request you to verify this and raise a separate ticket against javac as required ? Let me know if I have misunderstood something.
21-10-2015