Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8217272

Bad EnclosingMethod attribute on classes declared in lambdas

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 13
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      We have never made any promise regarding synthetic methods and in particular the ones we generate to implement lambda expressions. We expect that most users are not depending on the value of the EnclosingMethod attribute for local or anonymous inner classes inside lambda expressions. And those that did it were depending on an unspecified, unsupported feature. But it is also true that this change will impact reflection and applications relying on the current ETA
      Show
      We have never made any promise regarding synthetic methods and in particular the ones we generate to implement lambda expressions. We expect that most users are not depending on the value of the EnclosingMethod attribute for local or anonymous inner classes inside lambda expressions. And those that did it were depending on an unspecified, unsupported feature. But it is also true that this change will impact reflection and applications relying on the current ETA

      Description

      Summary

      The EnclosingMethod attribute of anonymous or local inner classes declared inside a lambda is not pointing to the method that enclosed the original declaration, which should be considered as the closest lexically enclosing method.

      Problem

      If an anonymous or local inner class is declared inside of a lambda, the EnclosingMethod attribute on that class refers to the synthetic lambda method rather than the method that enclosed the original declaration. The original method should be considered as the closest lexically enclosing method.

      Solution

      Point the EnclosingMethod attribute of inner classes declared inside a lambda to the original enclosing method. There is no need to change anything in the JLS but the compiler should be updated so that the EnclosingMethod attribute of anonymous or local inner classes declared inside a lambda point to the method enclosing the declaration.

      Specification

      JVMS 11 4.7.7: It is the responsibility of a Java compiler to ensure that the method identified via the method_index is indeed the closest lexically enclosing method of the class that contains this EnclosingMethod attribute.

      A synthetic method as the one that is generated for lambdas shouldn't be considered as the closest lexically enclosing method.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                webbuggrp Webbug Group
                Reviewed By:
                Maurizio Cimadamore
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: