java.lang.LinkageError: ClassCastException RuntimeDelegate.class Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of java.lang.LinkageError: ClassCastException RuntimeDelegate.class without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have this error

java.lang.LinkageError: ClassCastException: attempting to tomcat-debug-eclispe/wtpwebapps/xwiki-debug-eclipse/WEB-INF/lib/jsr311-api-1.1.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to tomcat-debug-eclispe/lib/jboss-jaxrs-api_2.0_spec-1.0.1.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.class

I’m using an open source wiki platform called xwiki https://github.com/xwiki/xwiki-platform

This platform somewhere include jsr311-api-1.1.1.jar and need it.

Now I want to connect through an XWiki Extension some keycloak feature and I need this

<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-admin-client --> <dependency> <groupId>org.keycloak</groupId> <artifactId>keycloak-admin-client</artifactId> <version>4.3.0.Final</version> </dependency>

As we can see here keycloak-admin-client need some provided dependencies including :

    <dependency>
        <groupId>org.jboss.spec.javax.ws.rs</groupId>
        <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
        <version>1.0.1.Final</version>
        <scope>provided</scope>
    </dependency>

and so from org.keycloak.admin.client.Keycloak I call

Keycloak.getInstance(keycloakUrl, keycloakRealm, keycloakUser, keycloakPwd, "admin-cli");

And at this moment my running applicatiom ( because everything run well ) give me the ClassCastException above.

It’s more a global jave ( JEE ) question here, I can’t give more code ’cause at the end you won t be able to build an XWiki/Keycloak running environment and reproduce the issue ( because in eclipse, throught unit test, outside the xwiki environment there is ofc no conflict and Keycloak.getInstance works fine ).

what can I do in this situation ? is there a maven way to avoid theses conflict ? maybe a class to reimplement ?

Environment :

tomcat 9.0.12
XWiki 10.6.1
Keycloak 4.3.0
Java 8

Answer

The reason why jsr311-api is embedded instead of just being a provided scope dependency is because JAX-RS API is not included in Java 9 anymore (it was in Java 8) and it was a problem for various application servers (did not noticed Tomcat 9 had decided to provide JAX-RS API but I guess it was to support Java 9). See https://jira.xwiki.org/browse/XWIKI-14743.

Now the reason why XWiki is still based on (the very old) JAX-RS 1 is that Restlet is based on JAX-RS 1 and JAX-RS 2 is not so great with retro compatibility so there is various problems when you try to run Restlet with it.

If you change Tomcat 9 for Tomcat 8 you won’t have startup error anymore. Unfortunately if keycloak require JAX-RS 2 it’s not going to be easy. Maybe an older version of keycloak is based on JAX-RS 1 but that’s indeed not very nice to have to downgrade it. I created https://jira.xwiki.org/browse/XWIKI-15588.

We are here to answer your question about java.lang.LinkageError: ClassCastException RuntimeDelegate.class - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji