JDK-4989710 : Static import broken on default package classes
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-02-05
  • Updated: 2004-06-04
  • Resolved: 2004-06-04
Related Reports
Duplicate :  
Relates :  
Relates :  
Description

Name: rmT116609			Date: 02/05/2004


FULL PRODUCT VERSION :
C:\>java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
When trying to carry out a static import on a class which is in the default package, the compiler fails with an error message.

This does not seem to happen if the class is in a named package, so importing the members of java.lang.Math (for instance) works fine, but if I were to implement my own class Test (rather than x.y.Test) the import fails.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to build and compile the files provided.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the method example1() to be imported. The JSR201 description specifies that the syntax should be:

import static TypeName . Identifier ;

A legitimate type name has been provided.
ACTUAL -
Fails with a compiler error - cannot find symbol. If I move the Example1 class into a non-default package (such that it becomes, for example, test.Example1) then the static import works fine.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
C:\>javac -version -cp c:\ -source 1.5 Example2.java
javac 1.5.0-beta
Example2.java:1: cannot find symbol
symbol: class Example1
import static Example1.*;
              ^
Example2.java:5: cannot find symbol
symbol  : method example1()
location: class Example2
      example1();
      ^
2 errors

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// File Example1.java - builds ok
public class Example1 {
   public static void example1() {
      System.out.println("Example1");
   }
}

// File Example2.java - fails on line 1.
import static Example1.*;

public class Example2 {
   public static void main(String... args) {
      example1();
   }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Move the class to be imported into a different package.
(Incident Review ID: 237397) 
======================================================================

Comments
EVALUATION classes from the unnamed namespace are not in scope in an import declaration. I believe the compiler is behaving as specified. ###@###.### 2004-02-05 True. ###@###.### 2004-06-04
05-02-2004