eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
689 stars 350 forks source link

Rest tests using jersey jars version 2.34 fails with java.lang.NoClassDefFoundError Could not initialize class org.glassfish.jersey.internal.inject.Providers__at org.glassfish.jersey.model.internal.ComponentBag.modelFor(ComponentBag.java:495) #5730

Closed deepthecoder closed 2 weeks ago

deepthecoder commented 2 weeks ago

I have a large project with more than 100 rest tests written to test verious endpoints. Currently the project uses JDK 8 and was using jersey 2.24.1 earlier. After encountering the CVE in jersey-core-common (https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-15250), I decided to upgrade the jersey version to 2.34 (the least version without any CVE). However, the tests seems to fail with one single failure which is as follows :

Caused By: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.internal.inject.Providersat org.glassfish.jersey.model.internal.ComponentBag.modelFor(ComponentBag.java:495)at org.glassfish.jersey.model.internal.ComponentBag.lambda_registerModel_10(ComponentBag.java:454)at org.glassfish.jersey.internal.Errors.process(Errors.java:292)at org.glassfish.jersey.internal.Errors.process(Errors.java:274)at org.glassfish.jersey.internal.Errors.process(Errors.java:205)at org.glassfish.jersey.model.internal.ComponentBag.registerModel(ComponentBag.java:446)at org.glassfish.jersey.model.internal.ComponentBag.register(ComponentBag.java:283)at org.glassfish.jersey.model.internal.CommonConfig.register(CommonConfig.java:417)__at org.glassfish.jersey.client.ClientConfig_State.register(ClientConfig.java:216)at org.glassfish.jersey.client.ClientConfig.register(ClientConfig.java:606)at org.glassfish.jersey.client.JerseyClient.register(JerseyClient.java:310)__at org.glassfish.jersey.client.JerseyClient.register(JerseyClient.java:56)

I checked if Providers class was missing from jersey-common but that was not the case.

I have seen some posts on StackOverflow (https://stackoverflow.com/questions/77443378/migrate-jersey-webservices-to-java-17-java-lang-noclassdeffounderror-could-not) wherein this same issue was being faced while migrating from JDK8 to JDK17. However, my case is different, I am still on JDK8.

Can someone please assist with this issue ?

deepthecoder commented 2 weeks ago

Below is the dependency tree for my rest jersey project :

[INFO] +- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile [INFO] +- org.glassfish.jersey.inject:jersey-hk2:jar:2.34:compile [INFO] | - org.glassfish.hk2:hk2-locator:jar:2.6.1:compile [INFO] | +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.6.1:compile [INFO] | +- org.glassfish.hk2:hk2-api:jar:2.6.1:compile [INFO] | - org.glassfish.hk2:hk2-utils:jar:2.6.1:compile [INFO] +- org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:jar:2.34:compile [INFO] | +- jakarta.servlet:jakarta.servlet-api:jar:4.0.3:compile [INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.34:compile [INFO] | +- org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar:2.34:compile [INFO] | | - org.glassfish.grizzly:grizzly-http-server:jar:2.4.4:compile [INFO] | | - org.glassfish.grizzly:grizzly-http:jar:2.4.4:compile [INFO] | | - org.glassfish.grizzly:grizzly-framework:jar:2.4.4:compile [INFO] | +- org.glassfish.grizzly:grizzly-http-servlet:jar:2.4.4:compile [INFO] | +- org.glassfish.jersey.core:jersey-server:jar:2.34:compile [INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:2.34:compile [INFO] | | - jakarta.validation:jakarta.validation-api:jar:2.0.2:compile [INFO] | - jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:compile [INFO] +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.34:compile [INFO] | - org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.34:compile [INFO] +- org.glassfish.jersey.core:jersey-common:jar:2.34:compile [INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile [INFO] | +- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:compile [INFO] | - org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile [INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.17.1:compile [INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.17.1:compile [INFO] | - ch.randelshofer:fastdoubleparser:jar:1.0.0:compile [INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.17.1:compile [INFO] +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.17.1:compile [INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile [INFO] | - jakarta.activation:jakarta.activation-api:jar:1.2.2:compile [INFO] +- org.apache.commons:commons-lang3:jar:3.14.0:compile [INFO] +- org.apache.httpcomponents.client5:httpclient5:jar:5.3.1:compile [INFO] | - org.apache.httpcomponents.core5:httpcore5-h2:jar:5.2.4:compile [INFO] +- org.apache.httpcomponents.core5:httpcore5:jar:5.2.4:compile [INFO] +- org.slf4j:slf4j-api:jar:2.0.12:compile [INFO] +- org.glassfish.jersey.media:jersey-media-multipart:jar:2.34:compile [INFO] | - org.jvnet.mimepull:mimepull:jar:1.9.13:compile [INFO] +- commons-io:commons-io:jar:2.16.1:compile [INFO] +- org.json:json:jar:20231013:compile [INFO] +- org.eclipse.persistence:eclipselink:jar:2.7.11:compile [INFO] | - org.eclipse.persistence:jakarta.persistence:jar:2.2.3:compile [INFO] +- org.codehaus.groovy:groovy:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-console:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-datetime:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-groovydoc:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-jmx:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-json:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-jsr223:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-macro:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-nio:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-servlet:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-sql:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-swing:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-templates:jar:3.0.19:compile [INFO] +- org.codehaus.groovy:groovy-xml:jar:3.0.19:compile [INFO] +- org.hsqldb:hsqldb:jar:jdk8:2.7.2:compile [INFO] +- org.javassist:javassist:jar:3.30.2-GA:compile [INFO] +- com.nimbusds:nimbus-jose-jwt:jar:9.37.3:compile [INFO] +- org.springframework:spring-jdbc:jar:5.3.32:runtime [INFO] | +- org.springframework:spring-beans:jar:5.3.32:compile [INFO] | +- org.springframework:spring-core:jar:5.3.32:compile [INFO] | | - org.springframework:spring-jcl:jar:5.3.32:compile [INFO] | - org.springframework:spring-tx:jar:5.3.32:compile [INFO] +- org.springframework:spring-context:jar:5.3.32:compile [INFO] | +- org.springframework:spring-aop:jar:5.3.32:compile [INFO] | - org.springframework:spring-expression:jar:5.3.32:compile [INFO] +- org.springframework:spring-orm:jar:5.3.32:compile [INFO] +- org.apache.ant:ant:jar:1.10.14:compile [INFO] +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.25.1:runtime [INFO] +- com.jayway.jsonpath:json-path:jar:2.9.0:compile [INFO] +- com.google.code.gson:gson:jar:2.11.0:compile [INFO] | - com.google.errorprone:error_prone_annotations:jar:2.27.0:compile [INFO] +- com.github.jsqlparser:jsqlparser:jar:4.9:compile [INFO] +- oracle.odi.adp:odi.adp.core:jar:1.0.0:provided [INFO] +- odi.adp.rest.common:odi-adp-rest-common:jar:0.0.1:provided [INFO] +- com.oracle.opss:jps-api:jar:12.2.1.4.0-190904.0147:compile [INFO] +- com.netsuite.jdbc:NQjc:jar:8.10.136.0:compile [INFO] +- com.oracle.netsuite.odi:Netsuite-ODI:jar:0.0.1:compile [INFO] +- com.oracle.opss:jps-common:jar:12.2.1.4.0-190904.0147:compile [INFO] +- com.oracle.opss:jps-internal:jar:12.2.1.4.0-190904.0147:compile [INFO] +- com.oracle.opss:jps-unsupported-api:jar:12.2.1.4.0-190904.0147:compile [INFO] +- com.oracle.opss:jps-ee:jar:12.2.1.4.0-190904.0147:runtime [INFO] +- com.oracle.opss:jps-se:jar:12.2.1.4.0-190904.0147:runtime [INFO] +- com.oracle.diagnostics:ojdl:jar:1.3.0-190912.0917.1974694:compile [INFO] +- com.oracle.em:identitystore:jar:12.2.1-1-0:compile [INFO] +- com.oracle.fmwshare:identitydirectory:jar:12.2.1-0-0:compile [INFO] +- org.apache-extras.beanshell:bsh:jar:2.1.1:compile [INFO] +- com.oracle.weblogic:org.glassfish.javax.json:jar:12.2.1-0-0:compile [INFO] +- com.oracle.ojdbc:ojdbc8:jar:19.3.0.0:compile [INFO] +- com.oracle.ojdbc:ojdbc8dms:jar:19.3.0.0:compile [INFO] +- com.oracle.ojdbc:ucp:jar:19.3.0.0:compile [INFO] +- com.oracle.database.security:osdt_cert:jar:21.3.0.0:compile [INFO] +- com.oracle.database.security:osdt_core:jar:21.3.0.0:compile [INFO] +- com.oracle.osdt.core:osdt_xmlsec:jar:8.0.0-190909.0221:runtime [INFO] +- com.oracle.database.security:oraclepki:jar:21.3.0.0:compile [INFO] +- com.oracle.diagnostics:dms:jar:1.3.0-190912.0917.1974694:compile [INFO] +- com.oracle.database.xml:xdb:jar:19.3.0.0:compile [INFO] +- oracle.fmwplatform.common:xmlparserv2:jar:12.2.0.1.0:compile [INFO] +- com.oracle.nlsrtl:orai18n-mapping-api:jar:19.3.0.0-8:compile [INFO] +- com.oracle.database.nls:orai18n:jar:19.3.0.0:compile [INFO] +- com.oracle.datadirect:fmwgenerictoken:jar:12.2.1.4.0-190725.1822.0231:runtime [INFO] +- com.oracle.oci.sdk:oci-java-sdk-shaded-full:jar:3.39.2:runtime [INFO] +- org.bouncycastle:bcpkix-jdk18on:jar:1.78.1:runtime [INFO] +- org.bouncycastle:bcutil-jdk18on:jar:1.78.1:runtime [INFO] +- org.bouncycastle:bcprov-jdk18on:jar:1.78.1:runtime [INFO] +- org.opentest4j:opentest4j:jar:1.1.1:test [INFO] +- org.glassfish.jersey.test-framework:jersey-test-framework-core:jar:2.31:test [INFO] | - junit:junit:jar:4.12:test [INFO] +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.34:compile [INFO] +- org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:jar:2.31:test [INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.5.2:test [INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.5.2:test [INFO] +- org.junit.platform:junit-platform-launcher:jar:1.5.2:test [INFO] +- org.junit.platform:junit-platform-runner:jar:1.5.2:test [INFO] +- org.junit.platform:junit-platform-commons:jar:1.5.2:test [INFO] +- org.junit.platform:junit-platform-suite-api:jar:1.5.2:test [INFO] +- org.junit.platform:junit-platform-engine:jar:1.5.2:test [INFO] - com.jayway.jsonpath:json-path-assert:jar:2.9.0:test [INFO] - org.hamcrest:hamcrest:jar:2.2:test [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 03:20 min [INFO] Finished at: 2024-08-26T20:18:30Z [INFO] ------------------------------------------------------------------------

jansupol commented 2 weeks ago

Try to run with java -verbose:class -Xdiag to see additional information.

deepthecoder commented 2 weeks ago

@jansupol Thanks for the help...I tried the below:

Tried upgrading to a relatively higher version of 2.38 of jersey and I see somewhat similar issue.

Caused by: javax/ws/rs/client/RxInvokerProvider [in thread \"qtp441001942-104\"] org.glassfish.jersey.internal.inject.Providers.getJaxRsProviderInterfaces(Providers.java:93) org.glassfish.jersey.internal.inject.Providers.(Providers.java:66)... 80 more [exec] [exec] 2024-08-26 23:22:39.789 WARNING 39 * Server responded with a response on thread grizzly-http-server-7 [exec] 39 < 500 [exec] 39 < Content-Type: application/json [exec] Caused By: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.internal.inject.Providers org.glassfish.jersey.model.internal.ComponentBag.modelFor(ComponentBag.java:495) org.glassfish.jersey.model.internal.ComponentBag.lambda$registerModel$10(ComponentBag.java:454) org.glassfish.jersey.internal.Errors.process(Errors.java:292) org.glassfish.jersey.internal.Errors.process(Errors.java:274) org.glassfish.jersey.internal.Errors.process(Errors.java:205) org.glassfish.jersey.model.internal.ComponentBag.registerModel(ComponentBag.java:446) org.glassfish.jersey.model.internal.ComponentBag.register(ComponentBag.java:283) org.glassfish.jersey.model.internal.CommonConfig.register(CommonConfig.java:417) org.glassfish.jersey.client.ClientConfig$State.register(ClientConfig.java:216) org.glassfish.jersey.client.ClientConfig.register(ClientConfig.java:607) org.glassfish.jersey.client.JerseyClient.register(JerseyClient.java:310) org.glassfish.jersey.client.JerseyClient.register(JerseyClient.java:56)

Also ran the java -verbose:class -Xdiag

And got the below results (in the same order):

[Loaded org.glassfish.jersey.internal.inject.Providers from file:/scratch/aime1/adestore/views/aime1_slc19duz/odi/odiqa/adp.tests/adp.tests.automation/trans_regression/adp/libs/odi-rest/jersey-common-2.38.jar [Loaded org.glassfish.jersey.internal.inject.Providers from file:/scratch/aime1/adestore/views/aime1_slc19duz/odi/odiqa/adp.tests/adp.tests.automation/trans_regression/adp/libs/core/jersey-common-2.38.jar] [Loaded org.glassfish.jersey.internal.inject.Providers$$Lambda$1287/0x00000007c1d76c28 from org.glassfish.jersey.internal.inject.Providers] [Loaded org.glassfish.jersey.internal.inject.Providers$ProviderRuntime from file:/scratch/aime1/adestore/views/aime1_slc19duz/odi/odiqa/adp.tests/adp.tests.automation/transregression/adp/libs/core/jersey-common-2.38.jar]

Do not see any conflicts here. Am I missing something ?

deepthecoder commented 2 weeks ago

After my upgrade to 2.38, I have made few changes in my classpath, which had fixed the issue, hence I am closing the issue. Thank you so much for the lead.