Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8138612 Do not retain declaration annotations on lambda formal parameters
  3. JDK-8140279

9.6.4.2: Do not retain declaration annotations on lambda formals

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Fixed
    • P4
    • 9
    • 8
    • specification

    Description

      Formal parameters of a lambda expression have no specified translation to class file artifacts. Consequently, it is difficult to see how to preserve declaration annotations on these formal parameters in the class file. (A similar issue arises for the names of the formal parameters, when javac -parameters is used.)

      In consultation with Brian Goetz, it was agreed that declaration annotations on formal parameters of lambda expressions should be exempted from the preserve-in-class-file semantics of RetentionPolicy.{CLASS,RUNTIME}, in line with the treatment of declaration annotations on local variables:

      "- If m has an element whose value is java.lang.annotation.RetentionPolicy.CLASS or java.lang.annotation.RetentionPolicy.RUNTIME, then a Java compiler must ensure that a is represented in the binary representation of the class or interface in which a appears, unless ***a*** annotates a local variable declaration ***or the formal parameter declaration of a lambda expression***.

      ***Annotations on the declaration of a local variable, or on the declaration of a formal parameter of a lambda expression, are never retained in the binary representation. In contrast, annotations on the type of a local variable declaration, and on the type of a formal parameter of a lambda expression, are retained in the binary representation if their annotation types specify a suitable retention policy. Note that it is not illegal for an annotation type to be meta-annotated with @Target(ElementType.LOCAL_VARIABLE) and @Retention(RetentionPolicy.CLASS) / @Retention(RetentionPolicy.RUNTIME).***"

      (Notice the text is "unless ***a*** annotates a local variable declaration or ..." -- JLS3 erroneously said "unless ***m*** annotates a local variable declaration" and the error persisted through JLS7 and JLS8.)

      Attachments

        Issue Links

          Activity

            People

              abuckley Alex Buckley
              abuckley Alex Buckley
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: