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

Cannot import classes from unnamed packages (1.4 regression)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • tools
    • None
    • generic
    • generic

      JDK 1.4 doesn't allow importing classes that don't belong to any package.
      This contradicts the JLS and is different from 1.3 behavior.

      Example:
       ------- A. java -------
      public class A {

          public void foo() {}

      }
       ------- B. java -------
      import B;

      public class B {

          public void bar() {
              new A().foo();
          }

      }

      ------- Sample run, JDK 1.3 (correct) --------
      % javac A.java B.java
      %
      ------- Sample run, JDK 1.4 (wrong) --------
      % javac A.java B.java
      B.java:1: '.' expected
      import B;
              ^
      1 error
      %
      ------- Java Language Specification, second edition requirement: ------

      7.5.1 Single-Type-Import Declaration

      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. The named type
      must be accessible (?6.6) or a compile-time error occurs.

            gafter Neal Gafter (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: