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

Static import broken on default package classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • specification
    • x86
    • windows_2000, windows_xp



      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)
      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: