Java Module doesn't work properly with shaded classes

Issue #550 open
Alexander Schepp created an issue

Thanks for fixing the Multi-Release issue, but it still doesn’t work properly.

We are having issues like these, because the Java Module system doesn’t play nice with the shaded classes:

java.lang.NoClassDefFoundError: com/nimbusds/jose/shaded/gson/ToNumberStrategy

Comments (8)

  1. Alexander Schepp reporter
    java.lang.NoClassDefFoundError: com/nimbusds/jose/shaded/gson/ToNumberStrategy
    
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.JWK.toJSONObject(JWK.java:677)
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.OctetKeyPair.toJSONObject(OctetKeyPair.java:966)
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.JWK.toJSONString(JWK.java:747)
        at nimbus.test@1.0-SNAPSHOT/com.example.Nimbus.createPrivateKey(Nimbus.java:13)
        at NimbusTest.test(NimbusTest.java:9)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    Caused by: java.lang.ClassNotFoundException: com.nimbusds.jose.shaded.gson.ToNumberStrategy
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        ... 8 more
    
    
    Process finished with exit code 255
    

  2. Vladimir Dzhuvinov

    This is odd. We’ve been using 9.39.1 in the OIDC SDK for example, and things built and seem to run fine. That is on openjdk 17.0.10 2024-01-16.

    I’m posting your pom.xml from the tar archive here:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.cgi.paidcontent</groupId>
        <artifactId>nimbus-test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>com.nimbusds</groupId>
                <artifactId>nimbus-jose-jwt</artifactId>
                <version>9.39.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.crypto.tink</groupId>
                <artifactId>tink</artifactId>
                <version>1.13.0</version>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>5.10.2</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>
    

  3. Vladimir Dzhuvinov

    mvn clean test gives here

    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /home/vd/tmp/nimbus-lib-issue/src/main/java/module-info.java:[2,35] module not found: com.nimbusds.jose.jwt
    [ERROR] /home/vd/tmp/nimbus-lib-issue/src/main/java/module-info.java:[3,35] module not found: com.google.crypto.tink
    

  4. Alexander Schepp reporter

    Hello, do you need more input from me? I was not available for the last 2 weeks.

    I reran the test today with the above example project. I noticed a small mistake on my side, that the test class is not in the right package, but the outcome is the same, just one less warning by the surefire plugin.

    Apache Maven 3.9.7
    Java version: 17.0.11 (OpenJDK)

    % mvn clean test
    
    [INFO] --- surefire:3.2.2:test (default-test) @ nimbus-test ---
    [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
    [INFO] 
    [INFO] -------------------------------------------------------
    [INFO]  T E S T S
    [INFO] -------------------------------------------------------
    [INFO] Running com.example.NimbusTest
    [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.161 s <<< FAILURE! -- in com.example.NimbusTest
    [ERROR] com.example.NimbusTest.test -- Time elapsed: 0.144 s <<< ERROR!
    java.lang.NoClassDefFoundError: com/nimbusds/jose/shaded/gson/ToNumberStrategy
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.JWK.toJSONObject(JWK.java:677)
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.OctetKeyPair.toJSONObject(OctetKeyPair.java:966)
        at com.nimbusds.jose.jwt@9.39.1/com.nimbusds.jose.jwk.JWK.toJSONString(JWK.java:747)
        at nimbus.test@1.0-SNAPSHOT/com.example.Nimbus.createPrivateKey(Nimbus.java:13)
        at nimbus.test@1.0-SNAPSHOT/com.example.NimbusTest.test(NimbusTest.java:10)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    Caused by: java.lang.ClassNotFoundException: com.nimbusds.jose.shaded.gson.ToNumberStrategy
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        ... 8 more
    

  5. Log in to comment