Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8291154

Create a non static nested class without enclosing class throws VerifyError

XMLWordPrintable

    • 16
    • b16
    • generic
    • generic

        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


              acobbs Archie Cobbs
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: