@@ -359,7 +359,8 @@ private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, S
359
359
try {
360
360
if (visited .add (sourceClass )) {
361
361
for (SourceClass annotation : sourceClass .getAnnotations ()) {
362
- if (!annotation .getMetadata ().getClassName ().startsWith ("java" ) && !annotation .isAssignable (Import .class )) {
362
+ String annName = annotation .getMetadata ().getClassName ();
363
+ if (!annName .startsWith ("java" ) && !annName .equals (Import .class .getName ())) {
363
364
collectImports (annotation , imports , visited );
364
365
}
365
366
}
@@ -525,11 +526,11 @@ public SourceClass asSourceClass(Class<?> classType) throws IOException, ClassNo
525
526
try {
526
527
// Sanity test that we can read annotations, if not fall back to ASM
527
528
classType .getAnnotations ();
529
+ return new SourceClass (classType );
528
530
}
529
531
catch (Throwable ex ) {
530
532
return asSourceClass (classType .getName ());
531
533
}
532
- return new SourceClass (classType );
533
534
}
534
535
535
536
/**
@@ -549,7 +550,7 @@ public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOExc
549
550
public SourceClass asSourceClass (String className ) throws IOException , ClassNotFoundException {
550
551
if (className .startsWith ("java" )) {
551
552
// Never use ASM for core java types
552
- return new SourceClass (this .resourceLoader .getClassLoader ().loadClass ( className ));
553
+ return new SourceClass (this .resourceLoader .getClassLoader ().loadClass (className ));
553
554
}
554
555
return new SourceClass (this .metadataReaderFactory .getMetadataReader (className ));
555
556
}
@@ -718,12 +719,18 @@ public SourceClass getSuperClass() throws IOException, ClassNotFoundException {
718
719
return asSourceClass (((MetadataReader ) this .source ).getClassMetadata ().getSuperClassName ());
719
720
}
720
721
721
- public Set <SourceClass > getAnnotations () throws IOException , ClassNotFoundException {
722
- Set <SourceClass > annotations = new LinkedHashSet <SourceClass >();
723
- for (String annotation : this .metadata .getAnnotationTypes ()) {
724
- annotations .add (getRelated (annotation ));
722
+ public Set <SourceClass > getAnnotations () throws IOException {
723
+ Set <SourceClass > result = new LinkedHashSet <SourceClass >();
724
+ for (String className : this .metadata .getAnnotationTypes ()) {
725
+ try {
726
+ result .add (getRelated (className ));
727
+ }
728
+ catch (Throwable ex ) {
729
+ // An annotation not present on the classpath is being ignored
730
+ // by the JVM's class loading -> ignore here as well.
731
+ }
725
732
}
726
- return annotations ;
733
+ return result ;
727
734
}
728
735
729
736
public Collection <SourceClass > getAnnotationAttributes (String annotationType , String attribute )
@@ -734,11 +741,11 @@ public Collection<SourceClass> getAnnotationAttributes(String annotationType, St
734
741
return Collections .emptySet ();
735
742
}
736
743
String [] classNames = (String []) annotationAttributes .get (attribute );
737
- Set <SourceClass > rtn = new LinkedHashSet <SourceClass >();
744
+ Set <SourceClass > result = new LinkedHashSet <SourceClass >();
738
745
for (String className : classNames ) {
739
- rtn .add (getRelated (className ));
746
+ result .add (getRelated (className ));
740
747
}
741
- return rtn ;
748
+ return result ;
742
749
}
743
750
744
751
private SourceClass getRelated (String className ) throws IOException , ClassNotFoundException {
@@ -748,7 +755,11 @@ private SourceClass getRelated(String className) throws IOException, ClassNotFou
748
755
return asSourceClass (clazz );
749
756
}
750
757
catch (ClassNotFoundException ex ) {
751
- // ignore
758
+ // Ignore -> fall back to ASM next, except for core java types.
759
+ if (className .startsWith ("java" )) {
760
+ throw ex ;
761
+ }
762
+ return new SourceClass (metadataReaderFactory .getMetadataReader (className ));
752
763
}
753
764
}
754
765
return asSourceClass (className );
0 commit comments