Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling to Proxy upon abstract class ends with java.lang.LinkageError: duplicate class definition [SPR-10242] #14875

Closed
spring-projects-issues opened this issue Jan 30, 2013 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 30, 2013

Jan Novotný opened SPR-10242 and commented

In 3.2 GA version of the Spring Framework I started to experience LingageErrors with cause of duplicate class definition. For example:

net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:64)
at net.sf.cglib.proxy.MethodProxy.helper(MethodProxy.java:120)
at net.sf.cglib.proxy.MethodProxy.init(MethodProxy.java:74)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:213)
at com.fg.metadata.business.aop.SpringCgLibIssue$AbstractMethodInterceptor.intercept(SpringCgLibIssue.java:58)
at com.fg.metadata.business.aop.SpringCgLibIssue$TestClassToProxy$$EnhancerByCGLIB$$f3b6125d.getSomeInt(<generated>)
at com.fg.metadata.business.aop.SpringCgLibIssue$TestClassToProxy$$FastClassByCGLIB$$4b5eb31.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at com.fg.metadata.business.aop.SpringCgLibIssue$SomeAdvice.invoke(SpringCgLibIssue.java:71)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.fg.metadata.business.aop.SpringCgLibIssue$TestClassToProxy$$EnhancerByCGLIB$$d3d37a7d.getSomeInt(<generated>)
at com.fg.metadata.business.aop.SpringCgLibIssue.testCallMethodOfAbstractClass(SpringCgLibIssue.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 36 more
Caused by: java.lang.LinkageError: duplicate class definition: com/fg/metadata/business/aop/SpringCgLibIssue$TestClassToProxy$$FastClassByCGLIB$$4b5eb31
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
... 42 more

Problem can be reproduced by the attached TestCase. Problem is quite weird - and is described in the attached test. Only first call to the implemented method of the abstract class ends with this exception, all succeeding calls finish ok.

Please don't ask why we are wrapping CgLib proxy into another Spring proxy. We have our reasons that are quite complex to explain.

This problem did not occur in previous versions of Spring (we use this mechanism since 2.5 version of Spring).

Thanks for help in advance.


Affects: 3.2 GA

Attachments:

Issue Links:

6 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This is caused by a CGLIB version mismatch: The CGLIB version you're using somehow gets in conflict with the CGLIB version that Spring is using since they're not the same (anymore).

Note that since Spring Framework 3.2, we're using repackaged versions of CGLIB 3.0 and ASM 4.0 in org.springframework.cglib/asm, respectively. Your test fails for me when combining standard CGLIB with Spring's repackaged version. However, it passes once your test uses org.springframework.cglib instead - just change your imports accordingly and you'll see it working.

So our recommended solution is simply to switch to Spring's version of CGLIB: That's the only one we guarantee to be compatible with CGLIB-proxied objects coming from Spring. This will remain true for future Spring versions as well.

Also, there doesn't seem to be anything we can do about it other than make Spring use the version of CGLIB from your classpath, which is what happened in Spring up until 3.1. There are quite a few drawbacks to that approach, though, including potential mismatch with other versions of CGLIB needed by other frameworks on the classpath, so we have no intentions to switch back.

Since it's rather unusual to do double proxying using CGLIB, I hope it's ok for you to make that switch to Spring's repackaged version of CGLIB. Let me know if any problems remain when using that one.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jan Novotný commented

Yes, you're right - using version from packages of Spring solves the problem. This is suitable solution for us - so we can close the issue now.

Thank you very much, your support is the best I've ever seen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants