How to solve IncompatibleClassChangeError


Posted by Steven

Today I wanted to introduce Degraph in my project to track cyclic dependencies. This got me a java.lang.IncompatibleClassChangeError which I had never seen before. Here’s a brief report how I solved this.

First, I added Degraph to my Maven-build project by adding this to my pom.xml:

  1. <degraph.version>0.1.2</degraph.version>
  2. <dependency>
  3. <groupId>de.schauderhaft.degraph</groupId>
  4. <artifactId>degraph-check</artifactId>
  5. <version>${degraph.version}</version>
  6. <scope>test</scope>
  7. </dependency>

I wrote this short test to make sure that all classes in my project are cycle-free:

  1. import static de.schauderhaft.degraph.check.JLayer.*;
  2. import static de.schauderhaft.degraph.check.JCheck.*;
  3. import static de.schauderhaft.degraph.check.Check.classpath;
  4.  
  5. import org.junit.Test;
  6.  
  7. import static org.hamcrest.core.Is.*;
  8.  
  9. import static org.junit.Assert.*;;
  10.  
  11.  
  12. public class DependencyTest {
  13.  
  14. @Test
  15. public void dependencyCyclicality() {
  16. assertThat(
  17. classpath().noJars().printTo("dependencyCyclicality.graphml")
  18. .including("de.myproject.client.**")
  19. ,is(violationFree())
  20. );
  21. }
  22.  
  23. @Test
  24. public void upwardsDependencies() {
  25. assertThat(
  26. classpath().noJars().printTo("upwardsDependencies.graphml")
  27. .including("de.myproject.client.**")
  28. ,is(violationFree())
  29. );
  30. }
  31. }

Running this test, I got:

  1. java.lang.IncompatibleClassChangeError: class de.schauderhaft.degraph.analysis.asm.GraphBuildingClassVisitor has interface org.objectweb.asm.ClassVisitor as super class
  2.  
  3. at java.lang.ClassLoader.defineClass1(Native Method)
  4. at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
  5. at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  6. at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
  7. at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
  8. at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
  9. at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
  10. at java.security.AccessController.doPrivileged(Native Method)
  11. at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
  12. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  13. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  14. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  15. at de.schauderhaft.degraph.analysis.asm.Analyzer$.de$schauderhaft$degraph$analysis$asm$Analyzer$$analyze$1(Analyzer.scala:18)
  16. at de.schauderhaft.degraph.analysis.asm.Analyzer$$anonfun$analyze$1$$anonfun$apply$1.apply(Analyzer.scala:36)
  17. at de.schauderhaft.degraph.analysis.asm.Analyzer$$anonfun$analyze$1$$anonfun$apply$1.apply(Analyzer.scala:35)
  18. at scala.collection.immutable.HashSet$HashSet1.foreach(HashSet.scala:322)
  19. at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:978)
  20. at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:978)
  21. at de.schauderhaft.degraph.analysis.asm.Analyzer$$anonfun$analyze$1.apply(Analyzer.scala:35)
  22. at de.schauderhaft.degraph.analysis.asm.Analyzer$$anonfun$analyze$1.apply(Analyzer.scala:32)
  23. at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
  24. at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
  25. at de.schauderhaft.degraph.analysis.asm.Analyzer$.analyze(Analyzer.scala:32)
  26. at de.schauderhaft.degraph.configuration.Configuration.createGraph(Configuration.scala:31)
  27. at de.schauderhaft.degraph.check.Check$$anon$1.apply(Check.scala:49)
  28. at de.schauderhaft.degraph.check.Check$$anon$1.apply(Check.scala:46)
  29. at de.schauderhaft.degraph.check.hamcrest.HamcrestWrapper.matchesSafely(HamcrestWrapper.scala:8)
  30. at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:65)
  31. at org.hamcrest.core.Is.matches(Is.java:26)
  32. at org.junit.Assert.assertThat(Assert.java:772)
  33. at org.junit.Assert.assertThat(Assert.java:738)
  34. at de.myproject.client.DependencyTest.dependencyCyclicality(DependencyTest.java:26)
  35. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  36. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  37. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  38. at java.lang.reflect.Method.invoke(Method.java:497)
  39. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
  40. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  41. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
  42. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  43. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
  44. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
  45. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
  46. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
  47. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
  48. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
  49. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
  50. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
  51. at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
  52. at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
  53. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
  54. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
  55. at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
  56. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  57. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  58. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  59. at java.lang.reflect.Method.invoke(Method.java:497)
  60. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

The assumption was that Degraph is apparently being executed against a different version of the asm library than it has been compiled to. To proof this, I had a look at the Maven dependencies. Using IntellijIDEA, I opened the dependency view via the “Maven Projects” view -> rightclick on Maven project -> “Show Dependencies …”.

As you can see, there are two “asm” nodes. Clicking them revealed that the version referenced by Degraph is 5.0.3 where the version referenced by querydsl-jpa is 3.3.1.

I tried updating querydsl-jpa from 2.9.0 to 3.7.3, which worked great:

In the new version, querydsl-jpa has no dependency to asm. This solves the conflict because there is only the one asm version referenced by Degraph. Now all tests work fine.

If the update of querydsl-jpa hadn't removed the dependency to asm, I would have tried to exclude it using dependency exclusions. This would work if qerydsl-jpa runs fine with the new version of asm provided by Degraph.

TL;DR

When running into an IncompatibleClassChangeError, check your Maven dependencies for multiple occurances of a library. Try to eliminate these.

Category: 
Share: