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

java.lang.NoClassDefFoundError: com/google/gson/internal/reflect/ReflectionAccessor #253

Closed
NickKanellos opened this issue Mar 12, 2022 · 2 comments

Comments

@NickKanellos
Copy link

NickKanellos commented Mar 12, 2022

Describe the bug

java.lang.NoClassDefFoundError: com/google/gson/internal/reflect/ReflectionAccessor
 at com.ibm.cloud.sdk.core.util.DynamicModelTypeAdapterFactory.(DynamicModelTypeAdapterFactory.java:77)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.registerTypeAdapters(GsonSingleton.java:77)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.createGson(GsonSingleton.java:53)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting(GsonSingleton.java:102)
 at com.ibm.cloud.sdk.core.http.RequestBuilder.bodyContent(RequestBuilder.java:417)
 at com.ibm.cloud.cloudant.v1.Cloudant.postDocument(Cloudant.java:825)

To Reproduce
call com.ibm.cloud.cloudant.v1.Cloudant.postDocument() using

<dependency>
     <groupId>com.ibm.cloud</groupId>
     <artifactId>cloudant</artifactId>
     <version>0.0.36</version>
</dependency>

and

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.9.0</version>
</dependency>

Unfortunately I can't use an earlier version of GSON because of this:
google/gson#1875
and this
google/gson#1902

Must gather (please complete the following information):

$ java --version
openjdk 16.0.2 2021-07-20
OpenJDK Runtime Environment Temurin-16.0.2+7 (build 16.0.2+7)
OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, sharing)

Additional context

@ricellis
Copy link
Member

ricellis commented Mar 14, 2022

You can track #236 for our update to support GSON 2.9, we are waiting on a fix in https://github.com/IBM/java-sdk-core.

FWIW the GSON problems you link to (that are motivating you to use 2.9) are caused by changes in visibility to internal classes in Java 9+, that were warnings prior to Java 16. This is exact reason why we declare support for running only on Java 8 and 11 currently.

It is possible to use this library with Java 16 and GSON 2.8.9 by supplying the JVM option to switch the error back to a warning or by breaking encapsulation - see IBM/java-sdk-core#127 (comment). It is worth noting that Java 16 is not a maintained Java version anyway; in Java 17 the option to switch the error back to a warning has been removed and breaking encapsulation is the only workaround.

@NickKanellos
Copy link
Author

@ricellis Excellent. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants