73
73
import org .springframework .core .type .classreading .MetadataReaderFactory ;
74
74
import org .springframework .core .type .filter .AssignableTypeFilter ;
75
75
import org .springframework .util .Assert ;
76
+ import org .springframework .util .CollectionUtils ;
76
77
import org .springframework .util .LinkedMultiValueMap ;
77
78
import org .springframework .util .MultiValueMap ;
78
79
import org .springframework .util .StringUtils ;
@@ -447,7 +448,7 @@ private void processImports(ConfigurationClass configClass, SourceClass currentS
447
448
}
448
449
449
450
if (checkForCircularImports && this .importStack .contains (configClass )) {
450
- this .problemReporter .error (new CircularImportProblem (configClass , this .importStack , configClass . getMetadata () ));
451
+ this .problemReporter .error (new CircularImportProblem (configClass , this .importStack ));
451
452
}
452
453
else {
453
454
this .importStack .push (configClass );
@@ -620,7 +621,7 @@ public void removeImportingClassFor(String importedClass) {
620
621
@ Override
621
622
public AnnotationMetadata getImportingClassFor (String importedClass ) {
622
623
List <AnnotationMetadata > list = this .imports .get (importedClass );
623
- return (list == null || list .isEmpty () ? null : list .get (list .size () - 1 ));
624
+ return (! CollectionUtils .isEmpty (list ) ? list .get (list .size () - 1 ) : null );
624
625
}
625
626
626
627
/**
@@ -634,7 +635,7 @@ public boolean contains(Object elem) {
634
635
Comparator <ConfigurationClass > comparator = new Comparator <ConfigurationClass >() {
635
636
@ Override
636
637
public int compare (ConfigurationClass first , ConfigurationClass second ) {
637
- return first .getMetadata ().getClassName ().equals (second .getMetadata ().getClassName ()) ? 0 : 1 ;
638
+ return ( first .getMetadata ().getClassName ().equals (second .getMetadata ().getClassName ()) ? 0 : 1 ) ;
638
639
}
639
640
};
640
641
return (Collections .binarySearch (this , configClass , comparator ) != -1 );
@@ -647,11 +648,11 @@ public int compare(ConfigurationClass first, ConfigurationClass second) {
647
648
* <li>com.acme.Bar</li>
648
649
* <li>com.acme.Baz</li>
649
650
* </ul>
650
- * return "ImportStack: [Foo->Bar->Baz]".
651
+ * return "[Foo->Bar->Baz]".
651
652
*/
652
653
@ Override
653
654
public String toString () {
654
- StringBuilder builder = new StringBuilder ("ImportStack: [" );
655
+ StringBuilder builder = new StringBuilder ("[" );
655
656
Iterator <ConfigurationClass > iterator = iterator ();
656
657
while (iterator .hasNext ()) {
657
658
builder .append (iterator .next ().getSimpleName ());
@@ -755,7 +756,16 @@ public Collection<SourceClass> getMemberClasses() throws IOException {
755
756
String [] memberClassNames = sourceReader .getClassMetadata ().getMemberClassNames ();
756
757
List <SourceClass > members = new ArrayList <SourceClass >(memberClassNames .length );
757
758
for (String memberClassName : memberClassNames ) {
758
- members .add (asSourceClass (memberClassName ));
759
+ try {
760
+ members .add (asSourceClass (memberClassName ));
761
+ }
762
+ catch (IOException ex ) {
763
+ // Let's skip it if it's not resolvable - we're just looking for candidates
764
+ if (logger .isDebugEnabled ()) {
765
+ logger .debug ("Failed to resolve member class [" + memberClassName +
766
+ "] - not considering it as a configuration class candidate" );
767
+ }
768
+ }
759
769
}
760
770
return members ;
761
771
}
@@ -834,12 +844,12 @@ public String toString() {
834
844
*/
835
845
private static class CircularImportProblem extends Problem {
836
846
837
- public CircularImportProblem (ConfigurationClass attemptedImport , Stack <ConfigurationClass > importStack , AnnotationMetadata metadata ) {
847
+ public CircularImportProblem (ConfigurationClass attemptedImport , Stack <ConfigurationClass > importStack ) {
838
848
super (String .format ("A circular @Import has been detected: " +
839
849
"Illegal attempt by @Configuration class '%s' to import class '%s' as '%s' is " +
840
- "already present in the current import stack [%s] " , importStack .peek ().getSimpleName (),
850
+ "already present in the current import stack %s " , importStack .peek ().getSimpleName (),
841
851
attemptedImport .getSimpleName (), attemptedImport .getSimpleName (), importStack ),
842
- new Location (importStack .peek ().getResource (), metadata ));
852
+ new Location (importStack .peek ().getResource (), attemptedImport . getMetadata () ));
843
853
}
844
854
}
845
855
0 commit comments