Odd compilation problem with javac and enumerations

For test purposes, I made three simple classes. Eclipse 3.2 (JDT) compiles them without error or warning. However, when trying to compile these classes with javac, I get the following errors:

/com/test/sub/TestCompile.java:19: cannot find symbol

symbol : class TestInterface

location: class com.test.sub.TestCompile

implements TestInterface

^

/com/test/sub/TestCompile.java:15: cannot find symbol

symbol : constructor TestCompileBase(com.test.sub.TestCompile.Constants)

location: class com.test.TestCompileBase

super(ONE);

^

These errors only occur if the TestCompile class is in a different package from the other two. The enumeration also seems to be part of the problem, since the error does not occur if I change the enum into a static nested class. I am using javac version 1.5.0_06 for Mac OS X. Does anyone know what's wrong? The classes are as follows:

// class 1

package com.test;

publicinterface TestInterface

{

public String getOrdinalString();

}

// class 2

package com.test;

publicclass TestCompileBase

{

public TestCompileBase(final TestInterface constant)

{

System.out.println(constant.getOrdinalString());

}

}

// class 3

package com.test.sub;

importstatic com.test.sub.TestCompile.Constants.ONE;

import com.test.TestCompileBase;

import com.test.TestInterface;

publicclass TestCompile

extends TestCompileBase

{

public TestCompile()

{

super(ONE);

}

publicenum Constants

implements TestInterface

{

ONE;

public String getOrdinalString()

{

return String.valueOf(ordinal());

}

}

}

// end test code

[3109 byte] By [dieresisa] at [2007-10-3 3:48:31]
# 1
I also confirmed this behavior for Windows JDK 1.5.0_08 and JDK 1.6.0-beta2.
dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 2
I submitted a bug report for this problem. Adding to my belief that it is a genuine bug is the fact that the JDT-compiled code runs without problems in the Sun JVM.
dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 3
Daft question: Are the 3 classes in the same file?If yes, I've an idea that you are only supposed to use the package command once at the start of the file. If not, then I've got nothing.
C_Heeneya at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 4
static import of something defined in that same sourcefile? Rather weird to say the least.
jwentinga at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 5

> Daft question: Are the 3 classes in the same file?

> If yes, I've an idea that you are only supposed to

> use the package command once at the start of the

> file.

No, each top-level declaration is in its own .java file. The three files are

com/test/TestInterface.java

com/test/TestCompileBase.java

com/test/sub/TestCompile.java

You are correct in thinking that only one package declaration per file is permitted.

Message was edited by:

dieresis

dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 6

> static import of something defined in that same sourcefile?

> Rather weird to say the least.

Why do you think it's weird? How else would you refer to the unqualified enum value?

In any case, I use such imports all the time in other code without problems, so I don't think it's relevant to this issue.

dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 7
So far I haven't received any response from Sun about the bug report I filed. I thought they were supposed to evaluate the bug within a few weeks. It's been months.
dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 8

This looks like a bug. I can't find the bug ID, if you have it, please let me know.

Workaround is to change the order of imports:

import com.test.TestCompileBase;

import com.test.TestInterface;

import static com.test.sub.TestCompile.Constants.ONE;

PeterAhea at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 9

> This looks like a bug. I can't find the bug ID, if you have it, please let me know.

The internal review ID is 784744. I never received a public bug # or any other response.

> Workaround is to change the order of imports:

> > import com.test.TestCompileBase;

> import com.test.TestInterface;

> import static com.test.sub.TestCompile.Constants.ONE;

Thanks. I'll try it.

dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...
# 10
> Workaround is to change the order of imports:This workaround worked for me using JDK 1.6 on Windows.
dieresisa at 2007-7-14 21:45:33 > top of Java-index,Developer Tools,Java Compiler...