org.springframework.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null

Spring JIRA | Wujek | 4 years ago
  1. 0

    I attach a project showcasing the problem. I have a {{PersonService}} that is 'mixed in' with aspectj introductions (I mix in a {{Runnable}}). Also, there is a Person domain class that should get the {{PersonService}} injected - it is a {{@Configurable}} and is woven with {{org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect}}. I use CGLib proxying for {{PersonService}} as it doesn't implement any interfaces (except for {{GroovyObject}}, which doesn't count here). {{PersonService}} creates an instance of Person in its constructor, and this causes the following exception: {noformat} Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [ class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [clas s test.service.PersonService]: ... {noformat} which gets repeated many many times. Somewhere in between I see the following: {noformat} nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at MainJava.main(MainJava.java:7) {noformat} The problem goes away when I: * disable the introduction of Runnable in {{MyAspect}} * comment out {{MyAspect}} bean from {{beans.xml}} (which disables the aspect, I suppose, and hence also disables the introduction) * move the '{{<context:load-time-weaver />}}' bit to be after all bean definitions I don't know if I am doing something illegal here as far as proxies, weaving, and cglib are concerned, but there is no information anywhere in the docs (as far as I can tell) about it being illegal. Also, when the xml element is moved to the end it works fine (except that Person objects created early on don't get injection). I attach a small project that shows the problem. Just issue: {noformat} ./gradlew clean run {noformat} in the project's folder. This should generate a log of exception output.

    Spring JIRA | 4 years ago | Wujek
    org.springframework.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null
  2. 0

    I attach a project showcasing the problem. I have a {{PersonService}} that is 'mixed in' with aspectj introductions (I mix in a {{Runnable}}). Also, there is a Person domain class that should get the {{PersonService}} injected - it is a {{@Configurable}} and is woven with {{org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect}}. I use CGLib proxying for {{PersonService}} as it doesn't implement any interfaces (except for {{GroovyObject}}, which doesn't count here). {{PersonService}} creates an instance of Person in its constructor, and this causes the following exception: {noformat} Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [ class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [class test.service.PersonService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: org.springframework.aop.framework.AopConfigException-->Could not generate CGLIB subclass of class [clas s test.service.PersonService]: ... {noformat} which gets repeated many many times. Somewhere in between I see the following: {noformat} nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at MainJava.main(MainJava.java:7) {noformat} The problem goes away when I: * disable the introduction of Runnable in {{MyAspect}} * comment out {{MyAspect}} bean from {{beans.xml}} (which disables the aspect, I suppose, and hence also disables the introduction) * move the '{{<context:load-time-weaver />}}' bit to be after all bean definitions I don't know if I am doing something illegal here as far as proxies, weaving, and cglib are concerned, but there is no information anywhere in the docs (as far as I can tell) about it being illegal. Also, when the xml element is moved to the end it works fine (except that Person objects created early on don't get injection). I attach a small project that shows the problem. Just issue: {noformat} ./gradlew clean run {noformat} in the project's folder. This should generate a log of exception output.

    Spring JIRA | 4 years ago | Wujek
    org.springframework.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null
  3. 0

    code > /dev/null: CodeGenerationException and proxies

    piotrturski.net | 1 week ago
    org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    ClassFormatError: Duplicate method name&signature from EnhancerBySpringCGLIB

    Stack Overflow | 2 months ago | user3416827
    java.lang.ClassFormatError: Duplicate method name&signature in class file org/springframework/scheduling/quartz/SchedulerFactoryBean$$EnhancerBySpringCGLIB$$bee87fe8$$EnhancerBySpringCGLIB$$6bb26669. Running the test using spring 4.0.6 framework works perfectly fine, but with 4.3.2, it's failing. When using 4.0.6, I was using cglib no dependencies library. With 4.3.2, the tests fail regardless of whether or not I use cglib. Spring embeds cglib and objensis into 4.3.* core library. "Furthermore, Spring Framework 4.3 embeds the updated ASM 5.1, CGLIB 3.2.4, and Objenesis 2.4 in spring-core.jar." SpringDocs We were using Java 8 and cglib-no-dep 2.2 with Spring framework 4.0.6. We tried running this code with and without the standalone library and see the same results. Stack trace: Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'getScheduler' threw exception; nested exception is org.springframework.cglib.core.CodeGenerationException:java.lang.reflect.InvocationTargetException >null
  6. 0

    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}}

    Spring JIRA | 3 years ago | Piotr Findeisen
    org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.cglib.core.CodeGenerationException

      java.lang.StackOverflowError-->null

      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean()
    2. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
      3. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      4. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaletonBeanRegistry.java:223)
      5. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      6. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      7. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
      7 frames
    3. Spring Context
      ClassPathXmlApplicationContext.<init>
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      3. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
      4. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
      4 frames
    4. Unknown
      MainJava.main
      1. MainJava.main(MainJava.java:7)
      1 frame