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

new Y().new Z() where Z is a static, inner class gets VerifyError.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: hotspot
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description

      algol% echo ${JAVA_HOME}
      /net/mulder.eng/export/mulder3/jdk12x/sparc/jdk1.2.1_L
      algol% ${JAVA_HOME}/bin/javac -d . X1.java
      algol% ${JAVA_HOME}/bin/java X
      j=10
      k=11
      k=11
      algol% ${JAVA_HOME}/bin/javac -d . X2.java
      algol% ${JAVA_HOME}/bin/java X
      Exception in thread "main" java.lang.VerifyError: (class: X, method: main signature: ([Ljava/lang/String;)V) Expecting to find unitialized object on stack
      algol% diff X1.java X2.java
      18c18
      < oz = oy.new Z();
      ---
      > oz = new Y().new Z();
      algol% cat X1.java

      class Y {
              static class Z extends Y {
                      static int j = 10;
                      int k = 11;
              }
              Y Zer() { return new Z(); }
      }
      class X {
              public static void main(String[] argv) {
                      Y oy = new Y();
                      System.out.println("j="+Y.Z.j);
                      // Static reference to non-static variable.
                      // System.out.println("k="+Y.Z.k);
                      Y oz;
                      oz = oy.Zer();
                      System.out.println("k="+((Y.Z)oz).k);
                      oz = oy.new Z();
                      System.out.println("k="+((Y.Z)oz).k);
              }
      }
      algol% cat X2.java

      class Y {
              static class Z extends Y {
                      static int j = 10;
                      int k = 11;
              }
              Y Zer() { return new Z(); }
      }
      class X {
              public static void main(String[] argv) {
                      Y oy = new Y();
                      System.out.println("j="+Y.Z.j);
                      // Static reference to non-static variable.
                      // System.out.println("k="+Y.Z.k);
                      Y oz;
                      oz = oy.Zer();
                      System.out.println("k="+((Y.Z)oz).k);
                      oz = new Y().new Z();
                      System.out.println("k="+((Y.Z)oz).k);
              }
      }


      This comes from third party code (Modena v 3.0 ciner112).

      Static inner classes are top level, meaning that they have no enclosing instance.
      This, apparently, does not prevent their having non-static fields and their being
      instantiated. If an attempt is made to instantiate outside the lexically
      enclosing class then an enclosing instance seems to be required as a qualifier of
      the new keyword (oy in oy.new Z() and new Y() in new Y().new Z() above).
      Is this behavior described in the inner class specification?

      The construct "oz=new Y.Z();" is allowed too. This one is easy to understand.

      In the above example, is the exception from X2.java valid? Or is it a bug?

      Exception in thread "main" java.lang.VerifyError: (class: X, method: main signature: ([Ljava/lang/String;)V) Expecting to find unitialized object on stack

      allan.jacobs@Eng 1999-04-02

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ajacobssunw Allan Jacobs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: