Buggy code:
public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { public static final int VALIDATION_NONE = XmlValidationModeDetector . VALIDATION_NONE ; public static final int VALIDATION_AUTO = XmlValidationModeDetector . VALIDATION_AUTO ; public static final int VALIDATION_DTD = XmlValidationModeDetector . VALIDATION_DTD ; public static final int VALIDATION_XSD = XmlValidationModeDetector . VALIDATION_XSD ; private static final Constants constants = new Constants ( XmlBeanDefinitionReader . class ) ; private int validationMode = XmlBeanDefinitionReader . VALIDATION_AUTO ; private boolean namespaceAware = false ; private Class documentReaderClass = DefaultBeanDefinitionDocumentReader . class ; private ProblemReporter problemReporter = new FailFastProblemReporter ( ) ; private ReaderEventListener eventListener = new EmptyReaderEventListener ( ) ; private SourceExtractor sourceExtractor = new NullSourceExtractor ( ) ; private NamespaceHandlerResolver namespaceHandlerResolver ; private DocumentLoader documentLoader = new DefaultDocumentLoader ( ) ; private EntityResolver entityResolver ; private ErrorHandler errorHandler = new org . springframework . util . xml . SimpleSaxErrorHandler ( logger ) ; private final XmlValidationModeDetector validationModeDetector = new XmlValidationModeDetector ( ) ; private final ThreadLocal < Set < EncodedResource > > resourcesCurrentlyBeingLoaded = new org . springframework . core . NamedThreadLocal < Set < EncodedResource > > ( "XML<seq2seq4repair_space>bean<seq2seq4repair_space>definition<seq2seq4repair_space>resources<seq2seq4repair_space>currently<seq2seq4repair_space>being<seq2seq4repair_space>loaded" ) ; public XmlBeanDefinitionReader ( BeanDefinitionRegistry registry ) { } public void setValidating ( boolean validating ) { } public void setValidationModeName ( String validationModeName ) { } public void setValidationMode ( int validationMode ) { } public int getValidationMode ( ) { } public void setNamespaceAware ( boolean namespaceAware ) { } public boolean isNamespaceAware ( ) { } public void setProblemReporter ( ProblemReporter problemReporter ) { } public void setEventListener ( ReaderEventListener eventListener ) { } public void setSourceExtractor ( SourceExtractor sourceExtractor ) { } public void setNamespaceHandlerResolver ( NamespaceHandlerResolver namespaceHandlerResolver ) { } public void setDocumentLoader ( DocumentLoader documentLoader ) { } public void setEntityResolver ( EntityResolver entityResolver ) { } protected EntityResolver getEntityResolver ( ) { } public void setErrorHandler ( ErrorHandler errorHandler ) { } public void setDocumentReaderClass ( Class documentReaderClass ) { } public int loadBeanDefinitions ( Resource resource ) throws BeanDefinitionStoreException { } public int loadBeanDefinitions ( EncodedResource encodedResource ) throws BeanDefinitionStoreException { Assert . notNull ( encodedResource , "EncodedResource<seq2seq4repair_space>must<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>null" ) ; if ( logger . isInfoEnabled ( ) ) { logger . info ( ( "Loading<seq2seq4repair_space>XML<seq2seq4repair_space>bean<seq2seq4repair_space>definitions<seq2seq4repair_space>from<seq2seq4repair_space>" + ( encodedResource . getResource ( ) ) ) ) ; } Set < EncodedResource > currentResources = this . resourcesCurrentlyBeingLoaded . get ( ) ; if ( currentResources == null ) { currentResources = new HashSet < EncodedResource > ( 4 ) ; this . resourcesCurrentlyBeingLoaded . set ( currentResources ) ; } if ( ! ( currentResources . add ( encodedResource ) ) ) { throw new BeanDefinitionStoreException ( ( ( "Detected<seq2seq4repair_space>cyclic<seq2seq4repair_space>loading<seq2seq4repair_space>of<seq2seq4repair_space>" + encodedResource ) + "<seq2seq4repair_space>-<seq2seq4repair_space>check<seq2seq4repair_space>your<seq2seq4repair_space>import<seq2seq4repair_space>definitions!" ) ) ; } try { InputStream inputStream = encodedResource . getResource ( ) . getInputStream ( ) ; try { InputSource inputSource = new InputSource ( inputStream ) ; if ( ( encodedResource . getEncoding ( ) ) != null ) { inputSource . setEncoding ( encodedResource . getEncoding ( ) ) ; } return doLoadBeanDefinitions ( inputSource , encodedResource . getResource ( ) ) ; } finally { inputStream . close ( ) ; } } catch ( IOException ex ) { throw new BeanDefinitionStoreException ( ( "IOException<seq2seq4repair_space>parsing<seq2seq4repair_space>XML<seq2seq4repair_space>document<seq2seq4repair_space>from<seq2seq4repair_space>" + ( encodedResource . getResource ( ) ) ) , ex ) ; } finally { currentResources . remove ( encodedResource ) ; if ( currentResources . isEmpty ( ) ) { <START_BUG> this . resourcesCurrentlyBeingLoaded . set ( null ) ; <END_BUG> } } } public int loadBeanDefinitions ( InputSource inputSource ) throws BeanDefinitionStoreException { } public int loadBeanDefinitions ( InputSource inputSource , String resourceDescription ) throws BeanDefinitionStoreException { } protected int doLoadBeanDefinitions ( InputSource inputSource , Resource resource ) throws BeanDefinitionStoreException { } protected int getValidationModeForResource ( Resource resource ) { } protected int detectValidationMode ( Resource resource ) { } public int registerBeanDefinitions ( Document doc , Resource resource ) throws BeanDefinitionStoreException { } @ SuppressWarnings ( "unchecked" ) protected BeanDefinitionDocumentReader createBeanDefinitionDocumentReader ( ) { } protected XmlReaderContext createReaderContext ( Resource resource ) { } protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver ( ) { } }

Fix:
this . resourcesCurrentlyBeingLoaded . remove ( ) ;