java.lang.LinkageError: ClassCastException

Unfortunately I can't tell you why this happened, but I can tell you how to get around this issue.

The problem was, that PowerMockito scanned tha class path and also added the RESTeasy classes (which are located within the package 'javax.ws.*'. Therefor the above mentioned RuntimeDelegate was loaded by the PowerMockito classloader and caused later the issue, that the class was compared against one from a different classloader.

To get around this issue, tell PowerMockito to ignore the javax.ws package when scanning for classes:

@PowerMockIgnore({"javax.ws.*"})

I faced the same issue when deploying my application to JBoss v6.1 - somehow understood that the problem was due to the same package structure of RuntimeDelegate.class existing within jesrey-core and jboss' jaxrs-api jar

Below is my pom.xml

    <!-- For Restful Client -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.8</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- For Jackson (JSON Utility) -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.5</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.9</version>
         <exclusions>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

After my war is deployed to JBoss, just removed resteasy.deployer folder from jboss' server\default\deployers folder. Ran my application and it worked.

I would be happy if someone explain why this error got resolved this way? (I think JBoss' has unnecessarily shipped with resteasy.deployers jars when developers could include the jars on their own in their apps) - Not to hide that I tried deploying my war on Tomcat and it worked smoothly.


I solved this problem by changing org.glassfish.jersey version in my pom.xml

Below is my pom.xml

 <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.1.1</version>
 </dependency>
 <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <version>2.31</version>
 </dependency>