JDK-4491314 : Can No Longer Import Classes from Default Package
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-08-13
  • Updated: 2001-08-13
  • Resolved: 2001-08-13
Related Reports
Duplicate :  
Description

Name: boT120536			Date: 08/13/2001


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)


Hello,

When using the JDK v1.3.1 compiler this problem does *not* occur. I have seen
nothing in the JLS that indicates the v1.3.1 compiler is behaving incorrectly
so I am assuming the problem is with the v1.4 compiler.

The problem is that a class in a non-default package cannot import a class from
the default package when compiling with the v1.4 compiler. I know this sounds
silly. Bear with me...

Let's say I have class named X in the default package:

public class X {}

Now let's say I have another class named A in the package named abc and class A
tries to import X:

package abc;

import X;

public class A {
   X x = new X();
   private static void main(String[] a) {}
}


Let's say I have this directory and file structure:

The directory "C:\Tony\" contains X.java
The directory "C:\Tony\abc\" contains A.java

Compiling X.java works fine.

I then try to compile A.java with c:\Tony\ as my current directory. So, from
the "C:\Tony\" directory I type:

javac abc\A.java

Several compiler errors are printed.

Theses errors do not occur if I compile using the v1.3.1 compiler. So, I'm not
sure if the problem is with the v1.3.1 compiler *not* producing error messages
or with the v1.4 compiler *producing* error messages. As I said, I can't find
anything in the JLS that prohibits classes within a package from importing
classes in the default package, so I believe the v1.3.1 compiler is correct.

As an aside, this issue came up because of an obfuscator we are using. The
obfuscator puts several (obfuscated) classes in the default package. Those
classes *not* obfuscated must then import these classes from the default
package. When we de-compile our classes and then try to re-compile them we have
this problem -- but only with the v1.4 compiler.

Can you please let me know if this is indeed a bug in the JDK v1.4 compiler?

Thanks much...
(Review ID: 129856) 
======================================================================

Comments
WORK AROUND Name: boT120536 Date: 08/13/2001 Use the JDK v1.3.1 compiler. ======================================================================
11-06-2004