RFR: 8291154: Create a non static nested class without enclosing class throws VerifyError [v2]

Vicente Romero vromero at openjdk.org
Fri Mar 24 05:22:31 UTC 2023


On Wed, 11 Jan 2023 21:49:39 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:

>> The fix for [JDK-8254321](https://bugs.openjdk.org/browse/JDK-8254321) opened a loophole where a Java source file that defines a static nested class `B` that extends a non-static nested class `A` no longer generates an error if `B` is nested within `A`.
>> 
>> Here's an example:
>> 
>> class StaticNestedNonStaticSuper {
>>     public abstract class NonStaticNested {
>>         public static class StaticNested extends NonStaticNested {
>>             public StaticNested() {
>>                 // where is StaticNestedNonStaticSuper.this for super() going to come from??
>>             }
>>         }
>>     }
>> }
>> 
>> 
>> Of course this is illegal because the non-static nested superclass requires an outer 'this' instance to be passed as the first argument to all of its constructors, but the static nested subclass has no such outer 'this' to provide. The compiler was proceeding anyway, resulting in unverifiable bytecode.
>> 
>> This PR adds a check for this situation. The check is added at the point in `Lower.java` where superclass constructor invocations in subclasses of non-static nested classes add the outer 'this' instance as a first parameter to `super()`.
>> 
>> I'm not sure if this is the most appropriate location for this additional check, but at least it is in an optimal place to observe the problem when it happens.
>
> Archie L. Cobbs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Simplify unit test.

looks good

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/11954#pullrequestreview-1356016734


More information about the compiler-dev mailing list