java.lang.IllegalStateException: not yet initialized

Terracotta | urciolo | 5 years ago
  1. 0

    Terracotta 3.5.1 On JBoss 6

    Terracotta | 5 years ago | urciolo
    java.lang.IllegalStateException: not yet initialized
  2. 0

    When a @Bean method returns an instance of a FactoryBean, Spring proxies the factory bean, redirecting calls to getObject() to applicationContext.getBean(). The relevant code reads: {code} /** * Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory * instead of creating a new instance. These proxies are created only when calling a FactoryBean from * within a Bean method, allowing for proper scoping semantics even when working against the FactoryBean * instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing, * it will not be proxied. This too is aligned with the way XML configuration works. */ private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory, final String beanName) throws InstantiationException, IllegalAccessException { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(fbClass); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setCallback(new MethodInterceptor() { @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if (method.getName().equals("getObject") && args.length == 0) { return beanFactory.getBean(beanName); } return proxy.invokeSuper(obj, args); // bug here? } }); return enhancer.create(); } {code} In the marked line, obj refers to the proxy object. Therefore, calls to methods other than getObject() are forwarded to the super implementation *on the proxy object*, which has a different state than the FactoryBean it proxies. This breaks the following usecase: {code} @Bean protected DBTool dbTool() { return new DBTool(hibernateSessionFactory()); } @Bean protected AnnotationSessionFactoryBean hibernateSessionFactory() { // hibernate setup goes here } {code} where DBTool has a method: {code} public void createSchema() { annotationSessionFactory.createDatabaseSchema(); } {code} which now throws {code} java.lang.IllegalStateException: SessionFactory not initialized yet at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.getSessionFactory(AbstractSessionFactoryBean.java:215) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.createDatabaseSchema(LocalSessionFactoryBean.java:989) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc.CGLIB$createDatabaseSchema$12(<generated>) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc$$FastClassBySpringCGLIB$$52787a0.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor$1.intercept(ConfigurationClassEnhancer.java:383) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc.createDatabaseSchema(<generated>) at ch.bedag.ste.app.cf.hibernate.framework.DBTool.createSchema(DBTool.java:23) {code} because the proxy object is a factory that has not been configured.

    Spring JIRA | 2 years ago | Adrian Moos
    java.lang.IllegalStateException: SessionFactory not initialized yet
  3. 0

    When a @Bean method returns an instance of a FactoryBean, Spring proxies the factory bean, redirecting calls to getObject() to applicationContext.getBean(). The relevant code reads: {code} /** * Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory * instead of creating a new instance. These proxies are created only when calling a FactoryBean from * within a Bean method, allowing for proper scoping semantics even when working against the FactoryBean * instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing, * it will not be proxied. This too is aligned with the way XML configuration works. */ private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory, final String beanName) throws InstantiationException, IllegalAccessException { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(fbClass); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setCallback(new MethodInterceptor() { @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if (method.getName().equals("getObject") && args.length == 0) { return beanFactory.getBean(beanName); } return proxy.invokeSuper(obj, args); // bug here? } }); return enhancer.create(); } {code} In the marked line, obj refers to the proxy object. Therefore, calls to methods other than getObject() are forwarded to the super implementation *on the proxy object*, which has a different state than the FactoryBean it proxies. This breaks the following usecase: {code} @Bean protected DBTool dbTool() { return new DBTool(hibernateSessionFactory()); } @Bean protected AnnotationSessionFactoryBean hibernateSessionFactory() { // hibernate setup goes here } {code} where DBTool has a method: {code} public void createSchema() { annotationSessionFactory.createDatabaseSchema(); } {code} which now throws {code} java.lang.IllegalStateException: SessionFactory not initialized yet at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.getSessionFactory(AbstractSessionFactoryBean.java:215) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.createDatabaseSchema(LocalSessionFactoryBean.java:989) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc.CGLIB$createDatabaseSchema$12(<generated>) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc$$FastClassBySpringCGLIB$$52787a0.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor$1.intercept(ConfigurationClassEnhancer.java:383) at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean$$EnhancerBySpringCGLIB$$2fba14bc.createDatabaseSchema(<generated>) at ch.bedag.ste.app.cf.hibernate.framework.DBTool.createSchema(DBTool.java:23) {code} because the proxy object is a factory that has not been configured.

    Spring JIRA | 2 years ago | Adrian Moos
    java.lang.IllegalStateException: SessionFactory not initialized yet
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    ModelRepository startup issue

    GitHub | 5 months ago | kaikreuzer
    java.lang.IllegalStateException: ScriptServiceUtil not initialized yet!
  6. 0

    [SPR-4968] Error "Singleton instance not initialized yet" triggered by toString call in case of circular references - Spring JIRA

    spring.io | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean1': Cannot resolve reference to bean 'bean2' while setting bean property 'friendBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean2': Cannot resolve reference to bean 'bean1' while setting bean property 'friendBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean1': Post-processing of the FactoryBean's object failed; nested exception is java.lang.IllegalStateException: Singleton instance not initialized yet

    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. java.lang.IllegalStateException

      not yet initialized

      at org.terracotta.modules.jboss.common.JBossLoaderNaming.getLoaderName()
    2. org.terracotta.modules
      JBossLoaderNaming.getLoaderName
      1. org.terracotta.modules.jboss.common.JBossLoaderNaming.getLoaderName(JBossLoaderNaming.java:65)[tim-jboss-common-2.2.2.jar:]
      1 frame
    3. JBoss ClassLoader
      BaseClassLoaderSystem$1.run
      1. org.jboss.classloader.spi.base.BaseClassLoader.<init>(BaseClassLoader.java:101)[jboss-classloader.jar:2.2.0.GA]
      2. org.jboss.classloader.spi.base.BaseClassLoaderSystem.createClassLoader(BaseClassLoaderSystem.java:188)[jboss-classloader.jar:2.2.0.GA]
      3. org.jboss.classloader.spi.base.BaseClassLoaderSystem$1.run(BaseClassLoaderSystem.java:126)[jboss-classloader.jar:2.2.0.GA]
      4. org.jboss.classloader.spi.base.BaseClassLoaderSystem$1.run(BaseClassLoaderSystem.java:123)[jboss-classloader.jar:2.2.0.GA]
      4 frames
    4. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)[:1.6.0_23]
      1 frame
    5. JBoss ClassLoader
      ClassLoaderSystem.registerClassLoaderPolicy
      1. org.jboss.classloader.spi.base.BaseClassLoaderSystem.registerClassLoaderPolicy(BaseClassLoaderSystem.java:122)[jboss-classloader.jar:2.2.0.GA]
      2. org.jboss.classloader.spi.ClassLoaderSystem.registerClassLoaderPolicy(ClassLoaderSystem.java:523)[jboss-classloader.jar:2.2.0.GA]
      3. org.jboss.classloader.spi.ClassLoaderSystem.registerClassLoaderPolicy(ClassLoaderSystem.java:465)[jboss-classloader.jar:2.2.0.GA]
      3 frames
    6. JBoss ClassLoading
      ClassLoaderPolicyModule.registerClassLoaderPolicy
      1. org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule.registerClassLoaderPolicy(ClassLoaderPolicyModule.java:146)[jboss-classloading.jar:2.2.0.GA]
      1 frame
    7. Java RT
      NativeMethodAccessorImpl.invoke0
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_23]
      1 frame