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

compiler permits to import class given by its non-canonical name

    Details

    • Subcomponent:
    • Resolved In Build:
      mantis
    • CPU:
      generic, x86, sparc
    • OS:
      generic, linux_redhat_7.1, solaris_7
    • Verification:
      Verified

      Description



      Name: ngR10089 Date: 05/24/2001



      JLS, 2nd Ed., 7.5.1 Single-Type-Import Declaration, says:

         "A single-type-import declaration imports a single type by giving its
          canonical name, making it available under a simple name in the class
          and interface declarations of the compilation unit in which the single-type
          import declaration appears.

               SingleTypeImportDeclaration:
                   import TypeName ;

          The TypeName must be the canonical name of a class or interface type;
          a compile-time error occurs if the named type does not exist."

       
      Java compiler jdk1.4.0beta-b65 permits to import class given by its
      non-canonical name.

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

      > javac -d . cls.java test.java
      > java -Xfuture p1.test
      6
      class p2.cls2$icl
      >

      Note, that when the units are compiled in another order, javac reports
      errors.

      >jac -d . test.java cls.java
      test.java:4: cannot resolve symbol
      symbol : class icl
      location: class p2.cls
      import p2.cls.icl;
                    ^
      test.java:11: cannot resolve symbol
      symbol : class icl
      location: class p1.test
      icl c = new p2.cls().new icl();
                      ^
      test.java:13: cannot resolve symbol
      symbol : class icl
      location: class p1.test
      out.println(icl.class);
                                  ^
      3 errors
      >

      -----------------test.java------------------
      package p1;
       
      import java.io.PrintStream;
      import p2.cls.icl;

      public class test {
      public static void main(String args[]) {
      System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
      }
      public static int run(String args[],PrintStream out) {
      icl c = new p2.cls().new icl();
      out.println(c.i);
      out.println(icl.class);
      return 0;
      }
      }
      ----------------------------------------------------
      -----------------cls.java------------------
      package p2;
       
      public class cls extends cls2 {
       
      }
      class cls2 {
      public class icl {
      public int i = 6;
      }
      }
      ----------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: