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

javac invalid "duplicate class" errors with sourcepath

XMLWordPrintable

    • b75
    • 7
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ALSO:

      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ALSO:

      java version "1.7.0_05"
      Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux heatonra-laptop 3.16.0-44-generic #59-Ubuntu SMP Tue Jul 7 02:07:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

      Other users have reported this to me, so this problem isn't limited to this OS.

      A DESCRIPTION OF THE PROBLEM :
      When javac is invoked with some particular sourcepaths, the compile fails with "duplicate class" errors, even though the purported class isn't really a duplicate class.

      This seems to happen only with certain source jars. If those same jars are extracted into a directory, and the directory is provided on the sourcepath instead of the jar, this does not seem to happen.

      REGRESSION. Last worked in version 6u43

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.6.0_30"
      Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      * From the command line, create a new directory and "cd" into it.
      * Download the ehcache-2.10.0-sources.jar at https://repo1.maven.org/maven2/net/sf/ehcache/ehcache/2.10.0/ehcache-2.10.0-sources.jar and put it into the new directory.
      * (Optional) Download the slf4j-api-1.7.12.jar at https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar and put it into the directory. This isn't required to reproduce the bug, but it eliminates some noise that makes it easier to see.
      * Extract into the new directory the "net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java" file from the ehcache sources jar.
      * Attempt to compile the ExtendedStatisticsImpl.java file with the ehcache sources jar on the sourcepath and (optionally) the slf4j jar on the classpath.

      For what it's worth, these are the commands on Linux (and probably Mac and Windows Cygwin):

      mkdir duplicate-class-bug
      cd duplicate-class-bug
      wget https://repo1.maven.org/maven2/net/sf/ehcache/ehcache/2.10.0/ehcache-2.10.0-sources.jar
      wget https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar
      jar -xvf ehcache-2.10.0-sources.jar net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java
      javac -classpath slf4j-api-1.7.12.jar -sourcepath ehcache-2.10.0-sources.jar net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java

      Note the invalid error message.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect there to be no "duplicate class" errors.

      In the above-mentioned scenario, the compile will still fail (complaining about missing classes on the classpath), but that's what I'm expecting. This is what happens when invoking the same "javac" command with Java 1.6.0_30.
      ACTUAL -
      Note the "duplicate class" errors.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      heatonra@heatonra-laptop:/tmp/duplicate-class-bug$ javac -classpath slf4j-api-1.7.12.jar -sourcepath ehcache-2.10.0-sources.jar net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java
      ehcache-2.10.0-sources.jar(net/sf/ehcache/util/concurrent/LongAdder.java):40: error: duplicate class: net.sf.ehcache.util.concurrent.LongAdder
      public class LongAdder extends Striped64 implements Serializable {
             ^
      ehcache-2.10.0-sources.jar(org/terracotta/statistics/derived/EventRateSimpleMovingAverage.java):27: error: cannot access LongAdder
      import org.terracotta.statistics.jsr166e.LongAdder;
                                              ^
        bad source file: ehcache-2.10.0-sources.jar(org/terracotta/statistics/jsr166e/LongAdder.java)
          file does not contain class org.terracotta.statistics.jsr166e.LongAdder
          Please remove or make sure it appears in the correct subdirectory of the sourcepath.
      ehcache-2.10.0-sources.jar(org/terracotta/statistics/derived/EventRateSimpleMovingAverage.java):18: error: cannot find symbol
      import static org.terracotta.statistics.Time.time;
      ^
        symbol: static time
        location: class


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      n/a (see steps to reproduce, above)
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The error appears to not happen when the source jar is extracted into a directory and the directory is provided on the sourcepath instead of the jar.

            rpatil Ramanand Patil (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: