lambda method naming changes in jdk 24
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jul 14 21:32:12 UTC 2025
Hi Egor,
I confirm that this change is deliberate. There were several changes
required to make JEP 513 (Flexible Constructor Bodies) work. Some of
these changes resulted in significant rewrites of the compiler backend
(to move lambda translation ahead of inner class translation). The bulk
of the work (and some history) is here:
https://github.com/openjdk/jdk/pull/19836
This change created some compatibility issues for serializable lambdas,
which were later addressed here:
https://github.com/openjdk/jdk/pull/20349
This latter change dropped a lot of accidental complexity from the javac
LambdaToInner pass, and that meant making the logic for computing the
names serializable and non-serializable lambdas more robust.
This meant that, unfortunately, the (unspecified) name of some
non-serializable lambda changed. This compatibility issue is described
in the associated CSR:
https://bugs.openjdk.org/browse/JDK-8337558
The difference you see is caused by when the name of the translated
lambda method is generated -- it used to be computed _after_ the end of
the lambda body, now it is computed _before_. This means that as soon as
we see the outermost lambda for `r3` we give it the first number -- then
the nested lambda for `r4` gets the second number.
This allows us to avoid having to "patch" the names of the translated
symbols, which minimizes the amount of mutation in our code, making it
less brittle. So, unless there's a big reason as to why these names
should go back the way they were, we'd like to keep the code the way it
is :-)
Cheers
Maurizio
On 11/07/2025 16:08, Egor Ushakov wrote:
> Hi everyone!
>
> it looks like in jdk 24 compiler started naming lambda methods
> slightly differently,
> consider the code:
> public class Lambdas1 {
> public static void main(String[]args) {
> Runnable r3 = () -> {
> Runnable r4 = () ->System.out.println(new Exception().getStackTrace()[0]);
> r4.run();
> System.out.println(new Exception().getStackTrace()[0]);
> };
> r3.run();
> }
> }
>
> with jdk 23 the output is:
> Lambdas1.lambda$main$*0*(Lambdas1.java:7)
> Lambdas1.lambda$main$*1*(Lambdas1.java:9)
>
> with jdk 24:
> Lambdas1.lambda$main$*1*(Lambdas1.java:4)
> Lambdas1.lambda$main$*0*(Lambdas1.java:6)
>
> I know that this is not specified anywhere, but Intellij IDEA relied
> on this and it caused issues with debugger features:
> https://youtrack.jetbrains.com/issue/IDEA-375811
>
> Was this change really intended? Could anyone please point me to the
> fix that caused this?
>
> Thanks!
> Egor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250714/9494bcde/attachment-0001.htm>
More information about the compiler-dev
mailing list