Skip to content

Maven plugin fails on Java 8 project due to ClassNotFoundException: kotlin.jdk7.AutoCloseableKt #2657

Description

@liblit

Description

I built UTBotJava-2023.10 using Java 17, after finding that both Java 8 and Java 11 resulted in build failures.

I added the UTBotJava Maven plugin to an open-source project's pom.xml, then tried to use Maven to run the utbot:generateTestsAndSarifReport task. The target project is still based on Java 8, so I set JAVA_HOME to a Java 8 JDK when running Maven. The utbot:generateTestsAndSarifReport task failed, reporting java.lang.ClassNotFoundException: kotlin.jdk7.AutoCloseableKt. Using a Java 17 JDK when running Maven fails even earlier, as the target application does not compile under Java 17.

To Reproduce

Steps to reproduce the behavior:

  1. Build UTBotJava using a Java 17 JDK. In my case, running on MacOS, I used:

    JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home ./gradlew publishToMavenLocal
  2. Check out nilzao/soapbox-race@5acac4da. Other revisions might exhibit the same problem, but that's the specific revision I used.

  3. Modify soapbox-race's pom.xml by adding the following lines to the <plugins> section:

    <plugin>
      <groupId>org.utbot</groupId>
      <artifactId>utbot-maven</artifactId>
      <version>2023.10-SNAPSHOT</version>
    </plugin>
  4. Using a Java 8 JDK, run Maven with the utbot:generateTestsAndSarifReport target:

    rm -rf target
    JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home mvn utbot:generateTestsAndSarifReport
  5. Also try using the same Java 17 JDK that was used to compile UTBotJava:

    rm -rf target
    JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home mvn utbot:generateTestsAndSarifReport
    

Expected behavior

Tests and a SARIF report should be generated.

Actual behavior

When running Maven using Java 8, failure due to java.lang.ClassNotFoundException: kotlin.jdk7.AutoCloseableKt.

When running Maven using Java 17, failure to compile the target application.

Visual proofs (screenshots, logs, images)

Environment

  • Java 8 and/or Java 17 JDKs as mentioned above
  • MacOS Ventura 13.4.1
  • nilzao/soapbox-race@5acac4da as the target application and Git commit hash for which tests should be generated
  • Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)

Activity

  1. liblit commented on Oct 10, 2023

    @liblit
    Author

    Additional clues, perhaps!

    If I manually remove ~/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7, then rerun the mvn command described above using a Java 8 JDK, I can see exactly which kotlin-stdlib-jdk7 dependency is being downloaded:

    ...
    [INFO] --- utbot:2023.10-SNAPSHOT:generateTestsAndSarifReport (default-cli) @ soapbox-race ---
    Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.6.21/kotlin-stdlib-jdk7-1.6.21.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.6.21/kotlin-stdlib-jdk7-1.6.21.pom (1.4 kB at 3.8 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.0/kotlin-stdlib-jdk7-1.8.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.0/kotlin-stdlib-jdk7-1.8.0.pom (1.4 kB at 92 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.0/kotlin-stdlib-jdk7-1.7.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.0/kotlin-stdlib-jdk7-1.7.0.pom (1.4 kB at 99 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.20/kotlin-stdlib-jdk7-1.7.20.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.20/kotlin-stdlib-jdk7-1.7.20.pom (1.4 kB at 154 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.0/kotlin-stdlib-jdk7-1.8.0.jar
    Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.0/kotlin-stdlib-jdk7-1.8.0.jar (963 B at 107 kB/s)
    [ERROR] Unexpected error while generating SARIF report
    java.lang.NoClassDefFoundError: kotlin/jdk7/AutoCloseableKt
    ...
    

    Looks like we're getting kotlin-stdlib-jdk7-1.8.0.jar. However, that specific jar does not contain an implementation of kotlin.jdk7.AutoCloseableKt:

    % unzip -t ~/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.0/kotlin-stdlib-jdk7-1.8.0.jar | grep AutoCloseableKt
    # (no grep results printed)

    Is the UnitTestBot Maven plugin requesting the wrong version of this kotlin-stdlib-jdk7 dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ctg-bugIssue is a bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions