Skip to content

Commit

Permalink
fix: catch NoClassDefFoundError when we try to import a class absent …
Browse files Browse the repository at this point in the history
…from the classpath (#1974)
  • Loading branch information
tdurieux authored and monperrus committed Apr 24, 2018
1 parent 13e769c commit f3032be
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/visitor/ImportScannerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ protected boolean classNamePresentInJavaLang(CtTypeReference<?> ref) {
try {
Class.forName("java.lang." + ref.getSimpleName());
presentInJavaLang = true;
} catch (ClassNotFoundException e) {
} catch (NoClassDefFoundError | ClassNotFoundException e) {
presentInJavaLang = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private CtType getOrLoadClass(String className) {
Class zeClass = this.getClass().getClassLoader().loadClass(className);
klass = this.factory.Type().get(zeClass);
return klass;
} catch (ClassNotFoundException e) {
} catch (NoClassDefFoundError | ClassNotFoundException e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ void setPackageOrDeclaringType(CtTypeReference<?> ref, CtReference declaring) {
CtPackageReference javaLangPackageReference = this.jdtTreeBuilder.getFactory().Core().createPackageReference();
javaLangPackageReference.setSimpleName("java.lang");
ref.setPackage(javaLangPackageReference);
} catch (ClassNotFoundException e) {
} catch (NoClassDefFoundError | ClassNotFoundException e) {
// in that case we consider the package should be the same as the current one. Fix #1293
ref.setPackage(jdtTreeBuilder.getContextBuilder().compilationUnitSpoon.getDeclaredPackage().getReference());
}
Expand Down

0 comments on commit f3032be

Please sign in to comment.