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

Compiler can give spurious errors when using -depend flag.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • generic, x86
    • solaris_2.5.1, windows_nt

      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

            wmaddoxsunw William Maddox (Inactive)
            tturnidgsunw Todd Turnidge (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: