Buggy code:
class ConfigurationClassParser { private final MetadataReaderFactory metadataReaderFactory ; private final ProblemReporter problemReporter ; private final ConfigurationClassParser . ImportStack importStack = new ConfigurationClassParser . ImportStack ( ) ; private final Set < ConfigurationClass > configurationClasses = new LinkedHashSet < ConfigurationClass > ( ) ; private final Stack < PropertySource < ? > > propertySources = new Stack < PropertySource < ? > > ( ) ; private final Environment environment ; private final ResourceLoader resourceLoader ; private final BeanDefinitionRegistry registry ; private final ComponentScanAnnotationParser componentScanParser ; public ConfigurationClassParser ( MetadataReaderFactory metadataReaderFactory , ProblemReporter problemReporter , Environment environment , ResourceLoader resourceLoader , BeanDefinitionRegistry registry ) { } public void parse ( String className , String beanName ) throws IOException { } public void parse ( Class < ? > clazz , String beanName ) throws IOException { } protected void processConfigurationClass ( ConfigurationClass configClass ) throws IOException { } protected void doProcessConfigurationClass ( ConfigurationClass configClass , AnnotationMetadata metadata ) throws IOException { } private void processImport ( ConfigurationClass configClass , String [ ] classesToImport , boolean checkForCircularImports ) throws IOException { if ( checkForCircularImports && ( this . importStack . contains ( configClass ) ) ) { this . problemReporter . error ( new ConfigurationClassParser . CircularImportProblem ( configClass , this . importStack , configClass . getMetadata ( ) ) ) ; } else { this . importStack . push ( configClass ) ; AnnotationMetadata importingClassMetadata = configClass . getMetadata ( ) ; for ( String candidate : classesToImport ) { MetadataReader reader = this . metadataReaderFactory . getMetadataReader ( candidate ) ; if ( new AssignableTypeFilter ( ImportSelector . class ) . match ( reader , metadataReaderFactory ) ) { try { ImportSelector selector = BeanUtils . instantiateClass ( Class . forName ( candidate ) , ImportSelector . class ) ; <START_BUG> ImportSelector . Context context = new ImportSelector . Context ( importingClassMetadata , this . registry ) ; <END_BUG> processImport ( configClass , selector . selectImports ( context ) , false ) ; } catch ( ClassNotFoundException ex ) { throw new IllegalStateException ( ex ) ; } } else { this . importStack . registerImport ( importingClassMetadata . getClassName ( ) , candidate ) ; processConfigurationClass ( new ConfigurationClass ( reader , null ) ) ; } } this . importStack . pop ( ) ; } } public void validate ( ) { } public Set < ConfigurationClass > getConfigurationClasses ( ) { } public Stack < PropertySource < ? > > getPropertySources ( ) { } public ConfigurationClassParser . ImportRegistry getImportRegistry ( ) { } interface ImportRegistry { String getImportingClassFor ( String importedClass ) { } } @ SuppressWarnings ( "serial" ) private static class ImportStack extends Stack < ConfigurationClass > implements ConfigurationClassParser . ImportRegistry { private Map < String , String > imports = new HashMap < String , String > ( ) ; public String getImportingClassFor ( String importedClass ) { } public void registerImport ( String importingClass , String importedClass ) { } @ Override public boolean contains ( Object elem ) { } @ Override public String toString ( ) { } } private static class CircularImportProblem extends Problem { public CircularImportProblem ( ConfigurationClass attemptedImport , Stack < ConfigurationClass > importStack , AnnotationMetadata metadata ) { } } }

Fix:
ImportSelectorContext context = new ImportSelectorContext ( importingClassMetadata , this . registry ) ;