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

Some generated access methods still violate access rules

    XMLWordPrintable

Details

    • beta
    • generic
    • solaris_7
    • Verified

    Description

      jvm throws IllegalAccessError exception when executing java class (see source below) using -verify option.

      /usr/jdk1.3.1/bin/java -verify QualifiedThisAndSuper_1
      Exception in thread "main" java.lang.IllegalAccessError: try to access method QualifiedThisAndSuper_1$AS.n()Ljava/lang/String; from class QualifiedThisAndSuper_1$A
              at QualifiedThisAndSuper_1$A.access$1101(QualifiedThisAndSuper_1.java:48)
              at QualifiedThisAndSuper_1$A$B$C.test(QualifiedThisAndSuper_1.java:104)
              at QualifiedThisAndSuper_1$A$B.test(QualifiedThisAndSuper_1.java:247)
              at QualifiedThisAndSuper_1$A.test(QualifiedThisAndSuper_1.java:252)
              at QualifiedThisAndSuper_1.main(QualifiedThisAndSuper_1.java:258)

      jdk1.3, and solaris jdk1.4.0-beta-b50 have same problem.

      Here is log of execution:
      <esi@jnana>/set/java/jdk1.4/solaris/bin/javac
      QualifiedThisAndSuper_1.java
      Java HotSpot(TM) Client VM warning: ValueGen::do_LoopEnter(...) not
      implemented yet
      Java HotSpot(TM) Client VM warning: ValueGen::do_LoopExit(...) not
      implemented yet
      <esi@jnana>/set/java/jdk1.4/solaris/bin/java -fullversion
      java full version "1.4.0-beta-b50"
      <esi@jnana>/set/java/jdk1.4/solaris/bin/java QualifiedThisAndSuper_1
      Java HotSpot(TM) Client VM warning: ValueGen::do_LoopEnter(...) not
      implemented yet
      Java HotSpot(TM) Client VM warning: ValueGen::do_LoopExit(...) not
      implemented yet
      foo
      bar
      baz
      foo
      bar
      baz
      foo
      bar
      baz
      foo
      bar
      baz
      foo
      bar
      baz
      foo
      bar
      baz


      ----------------------------------------------------
      QualifiedThisAndSuper_1.java
      ----------------------------------------------------
      /*
       * @test @(#)QualifiedThisAndSuper_1.java 1.1 98/07/24
       * @bug 4147520
       * @summary Verify correct implementation of qualified 'this' and 'super'.
       * @author maddox
       *
       * @run compile QualifiedThisAndSuper_1.java
       * @run main QualifiedThisAndSuper_1
       */

      public class QualifiedThisAndSuper_1 {

          public class AS {
              String s = "ass";
              private String t = "ast";
              protected String u = "asu";
              String m() { return "asm"; }
              private String n() { return "asn"; }
              protected String o() { return "aso"; }
          }

          public class BS {
              String s = "bss";
              private String t = "bst";
              protected String u = "bsu";
              String m() { return "bsm"; }
              private String n() { return "bsn"; }
              protected String o() { return "bso"; }
          }

          public class CS {
              String s = "css";
              private String t = "cst";
              protected String u = "csu";
              String m() { return "csm"; }
              private String n() { return "csn"; }
              protected String o() { return "cso"; }
          }


          void check(String expr, String result, String expected) {
              if (!result.equals(expected)) {
                  throw new Error("Evaluated "+ expr +
                                  " : result " + result + ", expected " + expected);
              }
          }

          public class A extends AS {
              A() { super(); }
              String s = "as";
              private String t = "at";
              protected String u = "au";
              String m() { return "am"; }
              private String n() { return "an"; }
              protected String o() { return "ao"; }
              public class B extends BS {
                  B() { super(); }
                  String s = "bs";
                  private String t = "bt";
                  protected String u = "bu";
                  String m() { return "bm"; }
                  private String n() { return "bn"; }
                  protected String o() { return "bo"; }
                  public class C extends CS {
                      C() { super(); }
                      String s = "cs";
                      private String t = "ct";
                      protected String u = "cu";
                      String m() { return "cm"; }
                      private String n() { return "cn"; }
                      protected String o() { return "co"; }
                      void test() {

                          check("this.m()", this.m(), "cm");

                          check("A.this.m()", A.this.m(), "am");
                          check("B.this.m()", B.this.m(), "bm");
                          check("C.this.m()", C.this.m(), "cm");

                          check("super.m()", super.m(), "csm");

                          check("A.super.m()", A.super.m(), "asm");
                          check("B.super.m()", B.super.m(), "bsm");
                          check("C.super.m()", C.super.m(), "csm");

                          // should re-use access methods.
                          check("A.super.m()", A.super.m(), "asm");
                          check("B.super.m()", B.super.m(), "bsm");
                          check("C.super.m()", C.super.m(), "csm");

                          //---

                          check("this.n()", this.n(), "cn");

                          check("A.this.n()", A.this.n(), "an");
                          check("B.this.n()", B.this.n(), "bn");
                          check("C.this.n()", C.this.n(), "cn");


                          check("super.n()", super.n(), "csn");



                          check("A.super.n()", A.super.n(), "asn");

                          check("B.super.n()", B.super.n(), "bsn");
                          check("C.super.n()", C.super.n(), "csn");

                          // should re-use access methods.
                          check("A.super.n()", A.super.n(), "asn");
                          check("B.super.n()", B.super.n(), "bsn");
                          check("C.super.n()", C.super.n(), "csn");

                          //---

                          check("this.o()", this.o(), "co");

                          check("A.this.o()", A.this.o(), "ao");
                          check("B.this.o()", B.this.o(), "bo");
                          check("C.this.o()", C.this.o(), "co");

                          check("super.o()", super.o(), "cso");

                          check("A.super.o()", A.super.o(), "aso");
                          check("B.super.o()", B.super.o(), "bso");
                          check("C.super.o()", C.super.o(), "cso");

                          // should re-use access methods.
                          check("A.super.o()", A.super.o(), "aso");
                          check("B.super.o()", B.super.o(), "bso");
                          check("C.super.o()", C.super.o(), "cso");

                          //---
                          
                          check("this.s", this.s, "cs");

                          check("A.this.s", A.this.s, "as");
                          check("B.this.s", B.this.s, "bs");
                          check("C.this.s", C.this.s, "cs");

                          //---

                          check("this.t", this.t, "ct");

                          check("A.this.t", A.this.t, "at");
                          check("B.this.t", B.this.t, "bt");
                          check("C.this.t", C.this.t, "ct");

                          //---
                          
                          check("this.u", this.u, "cu");

                          check("A.this.u", A.this.u, "au");
                          check("B.this.u", B.this.u, "bu");
                          check("C.this.u", C.this.u, "cu");

                          //---
                          
                          check("super.s", super.s, "css");

                          check("A.super.s", A.super.s, "ass");
                          check("B.super.s", B.super.s, "bss");
                          check("C.super.s", C.super.s, "css");

                          //---
                          
                          check("super.t", super.t, "cst");

                          check("A.super.t", A.super.t, "ast");
                          check("B.super.t", B.super.t, "bst");
                          check("C.super.t", C.super.t, "cst");

                          //---
                          
                          check("super.u", super.u, "csu");

                          check("A.super.u", A.super.u, "asu");
                          check("B.super.u", B.super.u, "bsu");
                          check("C.super.u", C.super.u, "csu");

                          //---

                          A.this.s = "foo";
                          System.out.println(A.this.s);
                          check("A.this.s", A.this.s, "foo");
                          B.this.s = "bar";
                          System.out.println(B.this.s);
                          check("B.this.s", B.this.s, "bar");
                          C.this.s = "baz";
                          System.out.println(C.this.s);
                          check("C.this.s", C.this.s, "baz");

                          A.this.t = "foo";
                          System.out.println(A.this.t);
                          check("A.this.t", A.this.t, "foo");
                          B.this.t = "bar";
                          System.out.println(B.this.t);
                          check("B.this.t", B.this.t, "bar");
                          C.this.t = "baz";
                          System.out.println(C.this.t);
                          check("C.this.t", C.this.t, "baz");

                          A.this.u = "foo";
                          System.out.println(A.this.u);
                          check("A.this.u", A.this.u, "foo");
                          B.this.u = "bar";
                          System.out.println(B.this.u);
                          check("B.this.u", B.this.u, "bar");
                          C.this.u = "baz";
                          System.out.println(C.this.u);
                          check("C.this.u", C.this.u, "baz");

                          A.super.s = "foo";
                          System.out.println(A.super.s);
                          check("A.super.s", A.super.s, "foo");
                          B.super.s = "bar";
                          System.out.println(B.super.s);
                          check("B.super.s", B.super.s, "bar");
                          C.super.s = "baz";
                          System.out.println(C.super.s);
                          check("C.super.s", C.super.s, "baz");

                          A.super.t = "foo";
                          System.out.println(A.super.t);
                          check("A.super.t", A.super.t, "foo");
                          B.super.t = "bar";
                          System.out.println(B.super.t);
                          check("B.super.t", B.super.t, "bar");
                          C.super.t = "baz";
                          System.out.println(C.super.t);
                          check("C.super.t", C.super.t, "baz");

                          A.super.u = "foo";
                          System.out.println(A.super.u);
                          check("A.super.u", A.super.u, "foo");
                          B.super.u = "bar";
                          System.out.println(B.super.u);
                          check("B.super.u", B.super.u, "bar");
                          C.super.u = "baz";
                          System.out.println(C.super.u);
                          check("C.super.u", C.super.u, "baz");

                      }
                  }
                  void test() throws Exception {
                      C c = new C();
                      c.test();
                  }
              }
              void test() throws Exception {
                  B b = new B();
                  b.test();
              }
          }
          
          public static void main(String[] args) throws Exception {
              A a = new QualifiedThisAndSuper_1().new A();
              a.test();
          }
      }

      ==========

      Here is a simplified test case:


      frog$ cat -n Q1.java
           1 public class Q1 {
           2
           3 public class AS {
           4 private String n() { return "asn"; }
           5 }
           6
           7 void check(String expr, String result, String expected) {
           8 if (!result.equals(expected)) {
           9 throw new Error("Evaluated "+ expr +
          10 " : result " + result + ", expected " + expected);
          11 }
          12 }
          13
          14 public class A extends AS {
          15 public class B {
          16 public class C {
          17 void test() {
          18 check("A.super.n()", A.super.n(), "asn");
          19 }
          20 }
          21 void test() throws Exception {
          22 check("A.super.n()", A.super.n(), "asn");
          23 C c = new C();
          24 c.test();
          25 }
          26 }
          27 void test() throws Exception {
          28 check("A.super.n()", A.super.n(), "asn");
          29 B b = new B();
          30 b.test();
          31 }
          32 }
          33
          34 public static void main(String[] args) throws Exception {
          35 A a = new Q1().new A();
          36 a.test();
          37 }
          38 }
      frog$ rm *.class && newjavac Q1.java && newjava Q1
      + /net/frog/gafter/gjc-neal/build/solaris-sparc/bin/java -Xfuture -Xbootclasspath/p:/net/frog/gafter/gjc-neal/gjclasses2 -classpath /net/frog/gafter/gjc-neal/gjclasses2:/net/frog/gafter/gjc-neal/make/tools/javac/gjc.jar:/net/frog/gafter/gjc-neal/make/tools/javac/gjcmain.jar com.sun.tools.javac.Main -classpath . Q1.java
      Exception in thread "main" java.lang.IllegalAccessError: try to access method Q1$AS.n()Ljava/lang/String; from class Q1$A
      at Q1$A.access$401(Q1.java:14)
      at Q1$A.test(Q1.java:28)
      at Q1.main(Q1.java:36)
      frog$

      Attachments

        Activity

          People

            gafter Neal Gafter
            tpreisle Thomas Preisler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: