Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8336492 Regression in lambda serialization
  3. JDK-8348584

Release Note: Minor Changes in Generated Code for Lambda Expressions

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 24
    • 24
    • tools

      Lambda expressions and method references are sometimes translated as methods by the `javac` compiler. As of this release, the name of the generated methods for non-serializable lambdas and method references has been updated. Such updates might be visible when inspecting the content of a class containing non-serializable lambdas and method references using core reflection.

      Moreover, the `EnclosingMethod` attribute for local and anonymous classes declared inside lambda expressions has been fixed to be compliant with JVMS 4.7.7 which states:

      > In particular, method_index must be zero if the current class was immediately enclosed in source code by an instance initializer, static initializer, instance variable initializer, or class variable initializer.

      This means that the following code:

      ```
      class Outer {
          Runnable action = () -> {
             class Inner() { }
             System.out.println(Inner.class.getEnclosingMethod());
          }
          
          public static void main(String[] args) {
             new Outer().action.run();
          }
      }
      ```

      will now, correctly, print `null`. That is, the local class `Inner` has no enclosing method. Earlier versions incorrectly reported the enclosing method of `Inner` to be the generated method for the lambda expression.

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: