manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.42k stars 125 forks source link

Duplicate class error when using apache commons Pair without importing java.util.Map #627

Open mattstermiller opened 1 month ago

mattstermiller commented 1 month ago

Describe the bug Using manifold-ext and the Pair type from org.apache.commons:commons-lang3 WITHOUT any import of java.util.Map causes a duplicate class compiler error:

java/util/Map.java:5: error: duplicate class: java.util.Map
public abstract interface Map<K, V> extends manifold.ext.rt.api.ICallHandler {

Simply adding import java.util.Map; to any java file in the project makes the error go away. But this is certainly not obvious and turns up as an unused import and could be auto-removed by some IDEs.

To Reproduce Steps to reproduce the behavior:

  1. Extract zip: duplicate-class.zip
  2. Run ./gradlew assemble

Expected behavior Project should compile without error.

Desktop (please complete the following information):

rsmckinney commented 1 month ago

@mattstermiller thanks for reporting this. A fix is on the way.

rsmckinney commented 1 month ago

During testing the issue appears only with Java 8. As a sanity check are you using Java 8? Thanks.

mattstermiller commented 1 month ago

No, I'm using Oracle's Java 17:

> java --version
java 17.0.9 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
rsmckinney commented 1 month ago

What version of gradle?

mattstermiller commented 1 month ago
> ./gradlew --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.9 (Oracle Corporation 17.0.9+11-LTS-201)
OS:           Windows 11 10.0 amd64
mattstermiller commented 1 month ago

I just updated my wrapper to the latest 8.10.2 and the issue persists.

rsmckinney commented 1 month ago

Please try with release 2024.1.37. I will continue to try to reproduce on JDKs greater than 8.

mattstermiller commented 1 month ago

A clean and build with these dependency updates gave the same error.

    implementation("systems.manifold:manifold-ext-rt:2024.1.37")
    annotationProcessor("systems.manifold:manifold-ext:2024.1.37")
rsmckinney commented 1 month ago

Are you using the duplicate-class.zip example? Using that I can only repro w JDK 8

rsmckinney commented 1 month ago

Screenshots for illustrating a successful JDK 17 build.

image

image

image

mattstermiller commented 4 weeks ago

Yes, I am using the same example I posted. Just to be sure, I re-downloaded and opened it from there. Same error.

My gradle settings look mostly the same: image

Are there any other local environment things I should check?

Thanks for looking into this, by the way.

rsmckinney commented 3 weeks ago

Did you set your Project SDK and Language level?

image

rsmckinney commented 3 weeks ago

if you are building from the command line, ensure you are performing a clean build. Also make sure there aren't any stray java daemon processes that gradle could be using in error. Otherwise, it should work. If it doesn't, try making a project from scratch by placing the build.gradle file in an empty directory and loading it in IJ as a project. Then add your source file and ensure gradle etc. is setup correctly.

apply plugin: 'java'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation("org.apache.commons:commons-lang3:3.17.0")
    implementation("systems.manifold:manifold-ext-rt:2024.1.37")
    annotationProcessor("systems.manifold:manifold-ext:2024.1.37")
}

tasks.withType(JavaCompile) {
    options.compilerArgs += ['-Xplugin:Manifold']
}
mattstermiller commented 1 week ago

Here's my project settings:

image

I tried several other SDKs in my list which are based on java 11 or 17 (clean then build) and they all fail with the same duplicate class error. I've made sure there are no other gradle daemons or java processes running. As far as making a project from scratch, that's what I've already done for this minimal repro project I provided.