-
Enhancement
-
Resolution: Fixed
-
P5
-
6, 7, 8
FULL PRODUCT VERSION :
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-1)
OpenJDK Server VM (build 14.0-b16, mixed mode)
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux thirtyseven 2.6.32-5-686-bigmem #1 SMP Tue Jun 1 05:38:08 UTC 2010 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Subtypes of types contained in the default package cannot be imported using single-type import statements. According to the JLS v3, single-type imports are to be provided with the canonical name of a class or interface type. The canonical name of a top-level type is the fully-qualified name of that type. The fully-qualified name of a top-level type declaration in the default package is the simple name of that type. Therefore, a class named "Test" in the default package should be imported using the import statement "import Test;".
The compiler seems to assume, however, that a single-type import requires a qualified name. This does not appear to be correct according to the JLS v3. Specifically, the example grammar in S18.1 shows, on page 592, a definition of ImportDeclaration which allows imports of simple names.
This bug was discovered while I was confirming my understanding of the syntax of import statements for the purposes of writing a Java parser. Our project will use the JLS-compliant syntax for the time being; it appears to be a superset of that currently allowed by the Java compiler which is, in this case, acceptable.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new source directory (henceforth termed $src). Create a directory $src/example. Create a file $src/Test.java with the following content:
public class Test { }
Create a file $src/example/Main.java with the following content:
package example;
import Test;
public class Main {
Test t;
}
Compile both source files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Binary output should be successfully generated. The output example/Main.class should contain a reference to the class defined by Test.class.
ACTUAL -
The compiler fails to compile, indicating that package Test does not exist.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
example/Main.java:2: '.' expected
import Test;
^
example/Main.java:2: ';' expected
import Test;
^
2 errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Contents of Test.java:
public class Test { }
Contents of example/Main.java:
package example;
import Test;
public class Main {
Test t;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround exists short of moving the default package class to another package.
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-1)
OpenJDK Server VM (build 14.0-b16, mixed mode)
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux thirtyseven 2.6.32-5-686-bigmem #1 SMP Tue Jun 1 05:38:08 UTC 2010 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Subtypes of types contained in the default package cannot be imported using single-type import statements. According to the JLS v3, single-type imports are to be provided with the canonical name of a class or interface type. The canonical name of a top-level type is the fully-qualified name of that type. The fully-qualified name of a top-level type declaration in the default package is the simple name of that type. Therefore, a class named "Test" in the default package should be imported using the import statement "import Test;".
The compiler seems to assume, however, that a single-type import requires a qualified name. This does not appear to be correct according to the JLS v3. Specifically, the example grammar in S18.1 shows, on page 592, a definition of ImportDeclaration which allows imports of simple names.
This bug was discovered while I was confirming my understanding of the syntax of import statements for the purposes of writing a Java parser. Our project will use the JLS-compliant syntax for the time being; it appears to be a superset of that currently allowed by the Java compiler which is, in this case, acceptable.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new source directory (henceforth termed $src). Create a directory $src/example. Create a file $src/Test.java with the following content:
public class Test { }
Create a file $src/example/Main.java with the following content:
package example;
import Test;
public class Main {
Test t;
}
Compile both source files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Binary output should be successfully generated. The output example/Main.class should contain a reference to the class defined by Test.class.
ACTUAL -
The compiler fails to compile, indicating that package Test does not exist.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
example/Main.java:2: '.' expected
import Test;
^
example/Main.java:2: ';' expected
import Test;
^
2 errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Contents of Test.java:
public class Test { }
Contents of example/Main.java:
package example;
import Test;
public class Main {
Test t;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround exists short of moving the default package class to another package.
- relates to
-
JDK-4420532 JLS2: Observability of a package is circularly defined
-
- Closed
-
-
JDK-4989710 Static import broken on default package classes
-
- Closed
-