Integrated: 8291154: Create a non static nested class without enclosing class throws VerifyError
Archie L. Cobbs
duke at openjdk.org
Fri Mar 24 14:16:44 UTC 2023
On Wed, 11 Jan 2023 21:33:08 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.
This pull request has now been integrated.
Changeset: f96aee74
Author: Archie L. Cobbs <archie.cobbs at gmail.com>
Committer: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/f96aee74010476a850175f7012c196e40a31c188
Stats: 22 lines in 3 files changed: 21 ins; 0 del; 1 mod
8291154: Create a non static nested class without enclosing class throws VerifyError
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/11954
More information about the compiler-dev
mailing list