JDK-8291154 : Create a non static nested class without enclosing class throws VerifyError
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-07-23
  • Updated: 2023-10-27
  • Resolved: 2023-03-24
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 17 JDK 21
17.0.10-oracleFixed 21 b16Fixed
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Creation of a static child class(AA) of an non static class(A) without enclosing class (EnclosingClass) throws VerifyError at runtime instead of an compiler error at compile time. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code provided

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compile time error
ACTUAL -
VerifyError at runtime:
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    EnclosingClass$A$AA.<init>()V @2: getfield
  Reason:
    Type uninitializedThis (current frame, stack[1]) is not assignable to 'EnclosingClass$A$AA'
  Current Frame:
    bci: @2
    flags: { flagThisUninit }
    locals: { uninitializedThis }
    stack: { uninitializedThis, uninitializedThis }
  Bytecode:
    0000000: 2a2a b400 01b7 0007 b1                 

	at EnclosingClass$A.create(EnclosingClass.java:12)
	at EnclosingClass.main(EnclosingClass.java:18)

---------- BEGIN SOURCE ----------
public class EnclosingClass {

    public abstract class A {

        public static class AA extends A {

        }

        public static A create() {
            return new AA();
        }

    }

    public static void main(String[] args) {
        A.create();
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Make A static  - it should not compile this way.

FREQUENCY : always



Comments
Fix request [17u] I backport this for parity with 17.0.10-oracle. Low risk, fixes a tool, javac, repro case available and simple fix. Clean backport. Test passes and fails without the fix. SAP nightly testing passed.
20-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1894 Date: 2023-10-19 12:36:24 +0000
19-10-2023

Changeset: f96aee74 Author: Archie L. Cobbs <archie.cobbs@gmail.com> Committer: Vicente Romero <vromero@openjdk.org> Date: 2023-03-24 14:13:21 +0000 URL: https://git.openjdk.org/jdk/commit/f96aee74010476a850175f7012c196e40a31c188
24-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11954 Date: 2023-01-11 21:33:08 +0000
11-01-2023

Some observations: Compilation error is thrown from JDK 8 till JDK 15: .\EnclosingClass.java:5: error: modifier static not allowed here public static class AA extends A { ^ .\EnclosingClass.java:10: error: non-static variable this cannot be referenced from a static context return new AA(); ^ .\EnclosingClass.java:9: error: Illegal static declaration in inner class EnclosingClass.A public static A create() { ^ modifier 'static' is only allowed in constant variable declarations 3 errors Since JDK 16+, there is no compilation issue. But VerifyError is thrown while executing the application. This is a regression issue.
27-07-2022

The issue is reproducible. After successful compilation, VerifyError is thrown when executing the application: Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
27-07-2022