org.springframework.cglib.core.CodeGenerationException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • When using: * cglib 2.2 directly * spring 3.2.5 (which wraps cglib 3.0) and spring's {{<aop:scoped-proxy/>}} feature it possible to run into {code} java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "$java/lang/Object$$FastClassByCGLIB$$3f697993" {code} Full stacktrace: {code} org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237) at org.springframework.cglib.reflect.FastClass$Generator.create(FastClass.java:64) at org.springframework.cglib.proxy.MethodProxy.helper(MethodProxy.java:121) at org.springframework.cglib.proxy.MethodProxy.init(MethodProxy.java:74) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:202) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at com.MyBean$$EnhancerByCGLIB$$f1fad224.toString(<generated>) at com.MyTest.testBeanWithAopScopedProxy(SpringAndCglibTest.java:122) .... Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219) ... 36 more Caused by: java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "$java/lang/Object$$FastClassByCGLIB$$3f697993" at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791) ... 41 more {code} h5. Attempt at analysis As far as I can understand, this seems to be caused by class naming conflict between CGLIB 2.2 and Spring-repackaged CGLIB. CGLIB's {{DefaultNamingPolicy}} solves name collisions using sort of "already used set", but obviously there are two such sets -- one CGLIB's and another Spring-CGLIB's -- so name collisions cannot be avoided and class generation fails. h5. Notes This is not only about probabilistic name clash. There seems to be nothing preventing Spring-CGLIB unconsciously re-using classes generated by non-Spring-CGLIB, which may be "programmed" with different behavior than desired. h5. Proposed solution Spring is already using non-default {{prefix}} ({{"org.springframework.cglib.empty.Object"}}, see {{DefaultNamingPolicy.getClassName}}), but this is not enough, since prefix is not used if provided explicitly. * Spring-repackaged CGLIB could have {{DefaultNamingPolicy.getTag()}} function changed to return something else than {{"ByCGLIB"}} * OR {{DefaultNamingPolicy}} could be called with different '{{source}}' -- see initialization of {{org.springframework.cglib.reflect.FastClass.SOURCE}}
    via by Piotr Findeisen,
  • When using: * cglib 2.2 directly * spring 3.2.5 (which wraps cglib 3.0) and spring's {{<aop:scoped-proxy/>}} feature it possible to run into {code} java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "$java/lang/Object$$FastClassByCGLIB$$3f697993" {code} Full stacktrace: {code} org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237) at org.springframework.cglib.reflect.FastClass$Generator.create(FastClass.java:64) at org.springframework.cglib.proxy.MethodProxy.helper(MethodProxy.java:121) at org.springframework.cglib.proxy.MethodProxy.init(MethodProxy.java:74) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:202) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at com.MyBean$$EnhancerByCGLIB$$f1fad224.toString(<generated>) at com.MyTest.testBeanWithAopScopedProxy(SpringAndCglibTest.java:122) .... Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219) ... 36 more Caused by: java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "$java/lang/Object$$FastClassByCGLIB$$3f697993" at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791) ... 41 more {code} h5. Attempt at analysis As far as I can understand, this seems to be caused by class naming conflict between CGLIB 2.2 and Spring-repackaged CGLIB. CGLIB's {{DefaultNamingPolicy}} solves name collisions using sort of "already used set", but obviously there are two such sets -- one CGLIB's and another Spring-CGLIB's -- so name collisions cannot be avoided and class generation fails. h5. Notes This is not only about probabilistic name clash. There seems to be nothing preventing Spring-CGLIB unconsciously re-using classes generated by non-Spring-CGLIB, which may be "programmed" with different behavior than desired. h5. Proposed solution Spring is already using non-default {{prefix}} ({{"org.springframework.cglib.empty.Object"}}, see {{DefaultNamingPolicy.getClassName}}), but this is not enough, since prefix is not used if provided explicitly. * Spring-repackaged CGLIB could have {{DefaultNamingPolicy.getTag()}} function changed to return something else than {{"ByCGLIB"}} * OR {{DefaultNamingPolicy}} could be called with different '{{source}}' -- see initialization of {{org.springframework.cglib.reflect.FastClass.SOURCE}}
    via by Piotr Findeisen,
  • attempted duplicate class definition
    via by Keir Lawson,
    • org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237) at org.springframework.cglib.reflect.FastClass$Generator.create(FastClass.java:64) at org.springframework.cglib.proxy.MethodProxy.helper(MethodProxy.java:121) at org.springframework.cglib.proxy.MethodProxy.init(MethodProxy.java:74) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:202) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at com.MyBean$$EnhancerByCGLIB$$f1fad224.toString(<generated>) at com.MyTest.testBeanWithAopScopedProxy(SpringAndCglibTest.java:122)
    No Bugmate found.