Buggy code:
public class SingletonBeanFactoryLocator implements BeanFactoryLocator { private static final String DEFAULT_RESOURCE_LOCATION = "classpath*:beanRefFactory.xml" ; protected static final Log logger = LogFactory . getLog ( SingletonBeanFactoryLocator . class ) ; private static final Map < String , BeanFactoryLocator > instances = new HashMap < String , BeanFactoryLocator > ( ) ; public static BeanFactoryLocator getInstance ( ) throws BeansException { } public static BeanFactoryLocator getInstance ( String selector ) throws BeansException { } private final Map < String , SingletonBeanFactoryLocator . BeanFactoryGroup > bfgInstancesByKey = new HashMap < String , SingletonBeanFactoryLocator . BeanFactoryGroup > ( ) ; private final Map < BeanFactory , SingletonBeanFactoryLocator . BeanFactoryGroup > bfgInstancesByObj = new HashMap < BeanFactory , SingletonBeanFactoryLocator . BeanFactoryGroup > ( ) ; private final String resourceLocation ; protected SingletonBeanFactoryLocator ( String resourceLocation ) { } public BeanFactoryReference useBeanFactory ( String factoryKey ) throws BeansException { synchronized ( this . bfgInstancesByKey ) { SingletonBeanFactoryLocator . BeanFactoryGroup bfg = this . bfgInstancesByKey . get ( this . resourceLocation ) ; if ( bfg != null ) { ( bfg . refCount ) ++ ; } else { if ( SingletonBeanFactoryLocator . logger . isTraceEnabled ( ) ) { SingletonBeanFactoryLocator . logger . trace ( ( ( "Factory<seq2seq4repair_space>group<seq2seq4repair_space>with<seq2seq4repair_space>resource<seq2seq4repair_space>name<seq2seq4repair_space>[" + ( this . resourceLocation ) ) + "]<seq2seq4repair_space>requested.<seq2seq4repair_space>Creating<seq2seq4repair_space>new<seq2seq4repair_space>instance." ) ) ; } BeanFactory groupContext = createDefinition ( this . resourceLocation , factoryKey ) ; bfg = new SingletonBeanFactoryLocator . BeanFactoryGroup ( ) ; bfg . definition = groupContext ; bfg . refCount = 1 ; this . bfgInstancesByKey . put ( this . resourceLocation , bfg ) ; this . bfgInstancesByObj . put ( groupContext , bfg ) ; try { initializeDefinition ( groupContext ) ; } catch ( BeansException ex ) { this . bfgInstancesByKey . remove ( this . resourceLocation ) ; this . bfgInstancesByObj . remove ( groupContext ) ; throw new BootstrapException ( ( ( ( ( ( "Unable<seq2seq4repair_space>to<seq2seq4repair_space>initialize<seq2seq4repair_space>group<seq2seq4repair_space>definition.<seq2seq4repair_space>" + "Group<seq2seq4repair_space>resource<seq2seq4repair_space>name<seq2seq4repair_space>[" ) + ( this . resourceLocation ) ) + "],<seq2seq4repair_space>factory<seq2seq4repair_space>key<seq2seq4repair_space>[" ) + factoryKey ) + "]" ) , ex ) ; } } try { <START_BUG> BeanFactory beanFactory = null ; <END_BUG> if ( factoryKey != null ) { beanFactory = bfg . definition . getBean ( factoryKey , BeanFactory . class ) ; } else if ( ( bfg . definition ) instanceof ListableBeanFactory ) { beanFactory = BeanFactoryUtils . beanOfType ( ( ( ListableBeanFactory ) ( bfg . definition ) ) , BeanFactory . class ) ; } else { throw new IllegalStateException ( ( "Factory<seq2seq4repair_space>key<seq2seq4repair_space>is<seq2seq4repair_space>null,<seq2seq4repair_space>and<seq2seq4repair_space>underlying<seq2seq4repair_space>factory<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>a<seq2seq4repair_space>ListableBeanFactory:<seq2seq4repair_space>" + ( bfg . definition ) ) ) ; } return new SingletonBeanFactoryLocator . CountingBeanFactoryReference ( beanFactory , bfg . definition ) ; } catch ( BeansException ex ) { throw new BootstrapException ( ( ( ( ( "Unable<seq2seq4repair_space>to<seq2seq4repair_space>return<seq2seq4repair_space>specified<seq2seq4repair_space>BeanFactory<seq2seq4repair_space>instance:<seq2seq4repair_space>factory<seq2seq4repair_space>key<seq2seq4repair_space>[" + factoryKey ) + "],<seq2seq4repair_space>from<seq2seq4repair_space>group<seq2seq4repair_space>with<seq2seq4repair_space>resource<seq2seq4repair_space>name<seq2seq4repair_space>[" ) + ( this . resourceLocation ) ) + "]" ) , ex ) ; } } } protected BeanFactory createDefinition ( String resourceLocation , String factoryKey ) { } protected void initializeDefinition ( BeanFactory groupDef ) { } protected void destroyDefinition ( BeanFactory groupDef , String selector ) { } private static class BeanFactoryGroup { private BeanFactory definition ; private int refCount = 0 ; } private class CountingBeanFactoryReference implements BeanFactoryReference { private BeanFactory beanFactory ; private BeanFactory groupContextRef ; public CountingBeanFactoryReference ( BeanFactory beanFactory , BeanFactory groupContext ) { } public BeanFactory getFactory ( ) { } public void release ( ) throws FatalBeanException { } } }

Fix:
BeanFactory beanFactory ;