Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"duplicate class" compiler errors #117

Closed
stoicflame opened this issue Aug 28, 2015 · 7 comments
Closed

"duplicate class" compiler errors #117

stoicflame opened this issue Aug 28, 2015 · 7 comments
Labels

Comments

@stoicflame
Copy link
Owner

As first reported at #103, Enunciate sometimes fails with "duplicate class" compiler errors that looks something like this:

[INFO] --- enunciate-maven-plugin:2.0.0-M.1:docs (default-cli) @ NewCRM ---
(... downloads lots of -source.jar ...)
[INFO] Reflections took 1760 ms to scan 94 urls, producing 9139 keys and 9139 values 
/home/garagoth/.m2/repository/net/sf/ehcache/ehcache/2.10.0/ehcache-2.10.0-sources.jar(net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java):39: error: cannot access Query
import org.terracotta.context.query.Query;
                                   ^
  bad source file: /home/garagoth/.m2/repository/net/sf/ehcache/ehcache/2.10.0/ehcache-2.10.0-sources.jar(org/terracotta/context/query/Query.java)
    file does not contain class org.terracotta.context.query.Query
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.
/home/garagoth/.m2/repository/net/sf/ehcache/ehcache/2.10.0/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 {
       ^
/home/garagoth/.m2/repository/net/sf/ehcache/ehcache/2.10.0/ehcache-2.10.0-sources.jar(org/terracotta/statistics/derived/EventParameterSimpleMovingAverage.java):27: error: cannot access LongAdder
import org.terracotta.statistics.jsr166e.LongAdder;
                                        ^
  bad source file: /home/garagoth/.m2/repository/net/sf/ehcache/ehcache/2.10.0/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.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.webcohesion.enunciate:enunciate-maven-plugin:2.0.0-M.1:docs (default-cli) on project NewCRM: Execution default-cli of goal com.webcohesion.enunciate:enunciate-maven-plugin:2.0.0-M.1:docs failed: Enunciate compile failed. -> [Help 1]
@stoicflame stoicflame added the bug label Aug 28, 2015
@stoicflame
Copy link
Owner Author

This has been tracked down to a bug in the Javac tool. The issue has been reported to Oracle, who have responded by assigning a review id: JI-9023928.

The issue can be reproduced as follows. Commands are specific to Linux, but would probably work on Mac or Windows:

$ mkdir duplicate-classes-bug
$ cd duplicate-classes-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

@jakub-bochenski
Copy link

@anton-johansson
Copy link
Contributor

I get this error sporadically. Not sure if it's related to this, but it looks very similar. I don't get a "duplicate class" message, but the rest looks similar.

10:28:21 [INFO] Building <artifactName> <artifactVersion>
10:28:21 [INFO] ------------------------------------------------------------------------
10:28:22 [INFO] 
10:28:22 [INFO] --- enunciate-maven-plugin:2.2.0:docs (default-cli) @ <artifactId> ---
10:28:22 [INFO] [ENUNCIATE] Using enunciate configuration at /home/jenkins/workspace/<jenkinsJob>/<groupId>/<artifactId>/enunciate.xml
10:28:23 [INFO] Reflections took 692 ms to scan 49 urls, producing 830 keys and 830 values 
10:28:25 [WARNING] [ENUNCIATE] [javac] [ERROR] com.webcohesion.enunciate.Enunciate$URLFileObject[file:/home/jenkins/.m2/repository/<projectPath>/<anotherArtifactId>/<artifactVersion>/<anotherArtifactId>-<artifactVersion>-sources.jar!/<projectPath>/domain/search/SearchField.java]:5:36 /home/jenkins/.m2/repository/<projectPath>/<anotherArtifactId>/<artifactVersion>/<anotherArtifactId>-<artifactVersion>-sources.jar!/<projectPath>/domain/search/SearchField.java:5: error: cannot access <anotherPackageName>.common.Presentation
10:28:25 [WARNING] [ENUNCIATE] [javac] /home/jenkins/.m2/repository/<projectPath>/<anotherArtifactId>/<artifactVersion>/<anotherArtifactId>-<artifactVersion>-sources.jar!/<projectPath>/domain/search/SearchField.java:5: error: cannot access <anotherPackageName>.common.Presentation
10:28:25 [WARNING] [ENUNCIATE] [javac] import <anotherPackageName>.common.Presentation;
10:28:25 [WARNING] [ENUNCIATE] [javac]                                    ^
10:28:25 [WARNING] [ENUNCIATE] [javac]   bad source file: /home/jenkins/.m2/repository/<projectPath>/<anotherArtifactId>/<artifactVersion>/<anotherArtifactId>-<artifactVersion>-sources.jar(<projectPath>/domain/common/Presentation.java)
10:28:25 [WARNING] [ENUNCIATE] [javac]     file does not contain class <anotherPackageName>.common.Presentation
10:28:25 [WARNING] [ENUNCIATE] [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.
10:28:25 [JENKINS] Archiving disabled
10:28:25 [JENKINS] Archiving disabled
10:28:25 [INFO] ------------------------------------------------------------------------
10:28:25 [INFO] BUILD FAILURE
10:28:25 [INFO] ------------------------------------------------------------------------
10:28:25 [INFO] Total time: 4.936s
10:28:25 [INFO] Finished at: Wed Feb 10 10:28:25 CET 2016
10:28:25 [INFO] Final Memory: 28M/389M
10:28:25 [INFO] ------------------------------------------------------------------------
10:28:25 [ERROR] Failed to execute goal com.webcohesion.enunciate:enunciate-maven-plugin:2.2.0:docs (default-cli) on project <artifactId>: Execution default-cli of goal com.webcohesion.enunciate:enunciate-maven-plugin:2.2.0:docs failed: Enunciate compile failed. -> [Help 1]
10:28:25 [ERROR] 
10:28:25 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
10:28:25 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
10:28:25 [ERROR] 
10:28:25 [ERROR] For more information about the errors and possible solutions, please read the following articles:
10:28:25 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
10:28:25 channel stopped
10:28:26 Finished: FAILURE

@seanf
Copy link

seanf commented Jul 14, 2016

The javac bug JDK-8143213 has been marked as a duplicate of https://bugs.openjdk.java.net/browse/JDK-8076104 (closed as fixed in Java 9).

(I just tried @stoicflame's reproducer with docker container java:9-b124-jdk, and I got a lot of compilation warnings and errors due to missing classes, but no "duplicate class" messages.)

A Java 8 backport of the fix is tracked here: https://bugs.openjdk.java.net/browse/JDK-8155198

@seanf
Copy link

seanf commented Sep 1, 2016

This problem ("error: duplicate class") happens 100% of the time if you use the maven-resources-plugin to package .java files inside jars for the GWT compiler, because target/classes ends up containing both my/package/Foo.java and my/package/Foo.class.

The correct way is to use a separate sources jar like this: http://stackoverflow.com/a/8731652/14379

@CharlieReitzel
Copy link

That JDK bug is caused by two classes with the same simple name, but in different packages, being found in the CLASSPATH. However, the enunciate issue appears to happen for application classes with simple names that are unique in the CLASSPATH, e.g. SceneChangeJobResource.

I find mvn clean install runs ok. But, once built, a mvn install fails with the "duplicate class" error. Easily reproduced. I am running JDK 8. But I think the root cause is the enunciate plugin is keeping copies of all the classes under ${projectDir}/target/enunicate and including both sets of classes in the CLASSPATH.

@pablo-dev
Copy link

pablo-dev commented Oct 2, 2020

I was having the duplicate class error using the version 2.11.1 (it also happens with 2.13.2).
I have compiled with mvn -X option and I realized that all the classes that I have in

<api-classes> <inlude pattern="..."/> ... </api-classes>

Appear twice under the 'Compiler sources: ' section.
What I have done to fix the error is using Set instead of List in Enunciate::getSourceFileURLs

schapsl added a commit to schapsl/enunciate that referenced this issue Feb 10, 2023
schapsl added a commit to schapsl/enunciate that referenced this issue Feb 10, 2023
schapsl added a commit to schapsl/enunciate that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants