JDK-8217272 : Bad EnclosingMethod attribute on classes declared in lambdas
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 13
  • Submitted: 2019-01-16
  • Updated: 2019-05-13
  • Resolved: 2019-05-13
Related Reports
CSR :  
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.


Comments
Moving to Approved.
13-05-2019

There is no other situation besides lambdas for which the patch will provoke a change There will be 83 instances affected in the whole JDK
13-05-2019

Moving to Provisional. Besides lambdas, are there other situations where this change causes a difference? If the experiment can be done easily, it would be helpful to know how many instances in the JDK would be affected by this change. A release note may be reasonable for the change.
01-05-2019

[~darcy] I have added a clarification in the `Solution` section stating that there is no need for any change to the current specification under this CSR
26-04-2019

Moving to Provisional. Before the request is finalized, please clarify whether or not any specifications are proposed to be changed under this CSR.
23-01-2019