0

I followed the advice given here to try some unit tests with spring aop enabled methods. However, I suspect that the repackaged cglib classes under spring-core and the cglib-nodep-2.2.jar conflict with each other, causing my class being proxied to be loaded by the classloader twice. This results in the following error:

Caused by: java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name:

Tools:

  1. easmock-3.0 (with cglib-nodep-2.2.jar transitive dependency)
  2. spring-x-4.0.0.RELEASE (with repackaged cglib of version ? classes)
  3. junit-4.8.1

Excluding the transitive cglib-nodep dependency didn't help obviously - all tests including non-sring-aop ones started failing too.

I tried the answer posted here too: cleaning up the target folder before running the tests again with no success.

Is this problem really because of the conflict of cglib versions like I thought it would be? If so, what is the right version I should use that would stop loading my class twice.

Community
  • 1
  • 1
mystarrocks
  • 4,040
  • 2
  • 36
  • 61
  • Check for the what all dependancies are being used. Check WEB-INF/lib folder or using Dependancy hierarchy view in eclipse pom editor to know the duplicate jars, remove the older version. – Santosh Joshi Feb 13 '14 at 13:37
  • I did, there was no duplicates in the cglib family. The spring people have repackaged the cglib classes into their spring-core, meaning cglib is not a transitive dependency that'll show up in the pom dependency view for us to spot the duplicate versions. – mystarrocks Feb 13 '14 at 13:50
  • you can checkout the following link: https://jira.springsource.org/browse/SPR-10242 – Santosh Joshi Feb 13 '14 at 13:56
  • That's exactly what I referred to, to conclude this could be a cglib version conflict! Like the post: https://jira.springsource.org/browse/SPR-10242?focusedCommentId=87833&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-87833 says, they want us to use the cglib-3.0 repackaged classes instead of any other cglib lib with spring-3.2. However in my case, cglib-nodep that comes with easymock contains more than just what's available with spring for it to work. That's the problem. – mystarrocks Feb 13 '14 at 14:08
  • Spiring 4 uses a repackaged version of cglib 3 as far as I know. It might be an ASM conflict down the drain. Have you tried upgrading cglib? – Rafael Winterhalter Feb 14 '14 at 08:14
  • I did. I tried with both cglib 3 and cglib 3.1 with no luck. – mystarrocks Feb 14 '14 at 18:25

1 Answers1

0
<properties>
    <java.version>1.7</java.version>
    <spring.version>4.0.3.RELEASE</spring.version>
    <cglib.version>2.2.2</cglib.version>
</properties>
Pang
  • 9,564
  • 146
  • 81
  • 122
Anadi
  • 1
  • 2