JDK-8067422 : Lambda method names are unnecessarily unstable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-12-15
  • Updated: 2016-07-19
  • Resolved: 2014-12-17
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 8 JDK 9
8u101Fixed 9 b44Fixed
Description
Currently, when  lambda names (for non-serializable lambdas) are generated, the exact name depends on the number of (non-serializable) lamdbas generated so far by the current javac instance. The reason is that the counter for lambda names is not per-file, but per-javac instance. For example, consider:
public class L1 {
    private Runnable r = () -> { };
}
public class L2 {
    private Runnable r = () -> { };
}
doing:
javac L1.java L2.java
will make L1's lambda use lambda$new$0 and L2's lambda$new$1, while:
javac L2.java L1.java
will lead to the opposite name assignment.

The problem seems to be simple: LambdaToMethod.LambdaAnalyzerPreprocessor.lambdaCount is not reset before starting with a new top-level.