Question

I'm working on a program that uses cglib, included as part of a large package of dependencies (version 2.1_3), and have written a new feature using parboiled processor to do some markdown to html conversion.

The problem arises with a dependency conflict. If I do nothing, all of my tests for the parboiled feature fail, with messages along the lines of:

java.lang.IncompatibleClassChangeError: org/parboiled/transform/ParserClassNode

And if I include the following exclusion

<exclusion>
     <groupId>asm</groupId>
     <artifactId>asm</artifactId>
</exclusion>

where my big dependency is declared, all of the parboiled tests will pass, but most of the others will fail, with messages like

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer

I am using pegdown 1.4.1

Any suggestions? Browsing the internet seems to suggest using a new version of asm (4.0 or later, the one in my project at the moment is 1.5.3) may help, but trying to exclude the asm I have and import the later one didn't help.

Was it helpful?

Solution

The problem is that cglib is hard to migrate. This is because:

  • newer cglib versions are not compatible to their earlier versions
  • newer ASM versions are not compatible to their earlier versions (cglib is built on top of asm)

The FAQ to ASM therefore recommends:

15 How to resolve conflicts between different ASM API versions available in a global classpath or within the same ClassLoader?

Tools and frameworks that are using ASM for bytecode processing (e.g. Hibernate, CGLIB, AspectWerkz) should repackage ASM code within their own name space. This can be automated with Jar Jar Links tool.

I recommend you to do the same with cglib. Move the entire dependency into a new package (create a independent name space) and only use this dependency. It is ugly, but it is the only solution. Other projects like Spring or Hibernate deal with cglib in the same manner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top