RFR: 8334252: Verifier error for lambda declared in early construction context

Archie Cobbs acobbs at openjdk.org
Thu Jun 13 21:10:14 UTC 2024


On Thu, 13 Jun 2024 21:03:15 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> When a lambda is declared in an early construction context, any reference to an outer instance must be acquired through the synthetic constructor rather than the synthetic outer instance field, because 'this' is not available yet.
>> 
>> The code in `LambdaToMethod.java` has logic for this using the `typesUnderConstruction` field, but that logic assumes that the only early construction context that can exist is within a `super()` or `this()` parameter list. While this was true previously, with the "flexible constructors" JEP 482, this is no longer the case.
>> 
>> So the fix is to update the logic for managing `typesUnderConstruction` to also include any statements prior to `super()` or `this()`.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java line 1440:
> 
>> 1438:             List<Frame> prevStack = frameStack;
>> 1439:             try {
>> 1440:                 if (TreeInfo.hasAnyConstructorCall(tree))   // start early construction context
> 
> Shouldn't we just test if we're in a constructor here?

Technically, not all constructors invoke `super()` or `this()`, albeit so far, `java.lang.Object` is the only exception.

Of course, it's unlikely that any day soon there will be other examples of this, or that the `java.lang.Object()` constructor will contain a lambda, but if either of those two things ever does happen then this code will still be correct :)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19707#discussion_r1638951404


More information about the compiler-dev mailing list