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

incorrect scoping for type name in qualified new expression.

XMLWordPrintable

    • hopper
    • x86, sparc
    • solaris_7, windows_98
    • Verified



      Name: ngR10089 Date: 01/19/2001



      JLS, 2nd Ed., 15.9.1 reads:

      "If a class instance creation expression does not declare an anonymous class,
      then:
           . . .

           Otherwise, the class instance creation expression is a qualified class
           instance creation expression. It is a compile-time error if Identifier is
           not the simple name (6.2) of an accessible (6.6) non-abstract inner
           class (8.1.2) T that is a member of the compile-time type of the Primary.
           It is also a compile-time error if Identifier is ambiguous (8.5). The
           class being instantiated is the class denoted by Identifier.

      The type of the class instance creation expression is the class type being
      instantiated."

      Java compiler jdk1.4.0beta-b47 reports error message while compiles program
      with the same name of declared top-level or inner class and first component
      of declared package.

      > java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b47)
      Java HotSpot(TM) Client VM (build 1.4beta-B47, mixed mode)

      > javac -d . test1.java
      test1.java:13: cannot resolve symbol
      symbol : class sqe
      location: class javasoft.sqe.tests.javasoft
              c1 = c0.new a();
                          ^
      1 error
      >

      > javac -d . test2.java
      test2.java:12: cannot resolve symbol
      symbol : class sqe
      location: class javasoft.sqe.tests.test2.javasoft
              c0 = new test2().new javasoft();
                                   ^
      test2.java:13: cannot resolve symbol
      symbol : class sqe
      location: class javasoft.sqe.tests.test2.javasoft
              c1 = new test2().new javasoft().new a();
                                   ^
      test2.java:13: cannot resolve symbol
      symbol : class a
      location: class javasoft.sqe.tests.test2
              c1 = new test2().new javasoft().new a();
                                                  ^
      3 errors
      >

      -----------------test1.java------------------
      package javasoft.sqe.tests;

      import java.io.PrintStream;

      public class test1 {
          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }
          public static int run(String argv[],PrintStream out) {
              javasoft c0;
              javasoft.a c1;
              c0 = new javasoft();
              c1 = c0.new a();

              out.println(c0.a0);
              out.println(c1.a0);

              return 0/*STATUS_PASSED*/;
          }
      }

      class javasoft {
          int a0 = 6;
          class a {
              int a0 = 5;
          }
      }
      ----------------------------------------------------
      -----------------test2.java------------------
      package javasoft.sqe.tests;

      import java.io.PrintStream;

      public class test2 {
          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }
          public static int run(String argv[],PrintStream out) {
              javasoft c0;
              javasoft.a c1;
              c0 = new test2().new javasoft();
              c1 = new test2().new javasoft().new a();

              out.println(c0.a0);
              out.println(c1.a0);

              return 0/*STATUS_PASSED*/;
          }
          class javasoft {
              int a0 = 6;
              class a {
                  int a0 = 5;
              }
          }
      }
      ----------------------------------------------------

      ======================================================================

            gafter Neal Gafter (Inactive)
            nvgsunw Nvg Nvg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: