There are cases where the compiler can give a meaningless message like:
./OneFile.java:1: Class OneFile already defined in OneFile.java.
public class OneFile extends B {
^
The above message basically claims that the class OneFile has been defined
twice. This is not the case...
Steps to reproduce:
Create the following file:
::::::::::::::
OneFile.java
::::::::::::::
public class OneFile extends B {
}
class A {
}
class B {
}
::::::::::::::
Compile it as so:
javac OneFile.java
Now comment out the declaration of B in OneFile. Perhaps you are planning
on moving it to its own file. The new version of OneFile looks like:
::::::::::::::
OneFile.java
::::::::::::::
public class OneFile extends B {
}
class A {
}
//class B {
//}
::::::::::::::
Now you compile with the -depend flag:
javac -depend OneFile.java
You get the following errors:
::::::::::::::
./OneFile.java:1: Class OneFile already defined in OneFile.java.
public class OneFile extends B {
^
./OneFile.java:4: Class A already defined in OneFile.java.
class A {
^
error: File ./OneFile.java does not contain class B as expected. Please adjust the class path so that the file does not appear in the unnamed package.
OneFile.java:1: Superclass B of class OneFile not found.
public class OneFile extends B {
^
4 errors
::::::::::::::
Note how misleading these messages are! The only real message in the lot is
the one complaining that OneFile.java does not contain class B as expected.
The rest complain of non-existent duplicate declarations.
Clearly there is a user error here; but the messages should not be so wacky,
even so.
Why This Happens:
During the second compilation of OneFile.java, it notices that it needs
to get class B. It finds the stale B.class in the directory. It notices
that B thinks it's defined in OneFile.java. So it opens and compiles OneFile.java *again*. Each class it finds, it thinks is a duplicate
declaration because it has already seen it before.
Related:
If we compile OneFile.java with the -depend flag, it will produce new
class files for OneFile and A. If another class references B and is compiled
with the -depend flag (while the old class file for B is sitting around), then
it will load the Binary for OneFile once and the Source for OneFile second,
causing the same duplicate declaration errors.
Proposed solution:
The compiler could try to detect these cases and either prevent the second load
or suppress the duplicate messages. I prefer the former.
Note:
Similar symptoms to 4037778, 4056065.
todd.turnidge@Eng 1998-02-04
./OneFile.java:1: Class OneFile already defined in OneFile.java.
public class OneFile extends B {
^
The above message basically claims that the class OneFile has been defined
twice. This is not the case...
Steps to reproduce:
Create the following file:
::::::::::::::
OneFile.java
::::::::::::::
public class OneFile extends B {
}
class A {
}
class B {
}
::::::::::::::
Compile it as so:
javac OneFile.java
Now comment out the declaration of B in OneFile. Perhaps you are planning
on moving it to its own file. The new version of OneFile looks like:
::::::::::::::
OneFile.java
::::::::::::::
public class OneFile extends B {
}
class A {
}
//class B {
//}
::::::::::::::
Now you compile with the -depend flag:
javac -depend OneFile.java
You get the following errors:
::::::::::::::
./OneFile.java:1: Class OneFile already defined in OneFile.java.
public class OneFile extends B {
^
./OneFile.java:4: Class A already defined in OneFile.java.
class A {
^
error: File ./OneFile.java does not contain class B as expected. Please adjust the class path so that the file does not appear in the unnamed package.
OneFile.java:1: Superclass B of class OneFile not found.
public class OneFile extends B {
^
4 errors
::::::::::::::
Note how misleading these messages are! The only real message in the lot is
the one complaining that OneFile.java does not contain class B as expected.
The rest complain of non-existent duplicate declarations.
Clearly there is a user error here; but the messages should not be so wacky,
even so.
Why This Happens:
During the second compilation of OneFile.java, it notices that it needs
to get class B. It finds the stale B.class in the directory. It notices
that B thinks it's defined in OneFile.java. So it opens and compiles OneFile.java *again*. Each class it finds, it thinks is a duplicate
declaration because it has already seen it before.
Related:
If we compile OneFile.java with the -depend flag, it will produce new
class files for OneFile and A. If another class references B and is compiled
with the -depend flag (while the old class file for B is sitting around), then
it will load the Binary for OneFile once and the Source for OneFile second,
causing the same duplicate declaration errors.
Proposed solution:
The compiler could try to detect these cases and either prevent the second load
or suppress the duplicate messages. I prefer the former.
Note:
Similar symptoms to 4037778, 4056065.
todd.turnidge@Eng 1998-02-04
- duplicates
-
JDK-4306482 # Need improved diagnostics for misplaced source files and ill-formed classpath
-
- Closed
-