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

Spring JIRA | Wujek | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  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

    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