[java] Avoid errors upon resolving invalid classes

- Resolves #328
 - Take the chance to simplify some error handling
(`NoClassDefFoundError` extends `LinkageError`)
This commit is contained in:
Juan Martín Sotuyo Dodero
2017-10-10 12:08:52 -03:00
parent da8ac69f4e
commit dbe0168865
2 changed files with 4 additions and 3 deletions

View File

@ -532,6 +532,9 @@ public class TypeSet {
return resolver.resolve(name);
} catch (ClassNotFoundException cnfe) {
// ignored, maybe another resolver will find the class
} catch (LinkageError le) {
// we found the class, but there is a problem with it (see https://github.com/pmd/pmd/issues/328)
return null;
}
}
}

View File

@ -1298,8 +1298,6 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
myType = pmdClassLoader.loadClass(qualifiedName);
} catch (ClassNotFoundException e) {
myType = processOnDemand(qualifiedName);
} catch (NoClassDefFoundError e) {
myType = processOnDemand(qualifiedName);
} catch (LinkageError e) {
myType = processOnDemand(qualifiedName);
}
@ -1430,7 +1428,7 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
String strName = anImportDeclaration.getImportedName();
String fieldName = strName.substring(strName.lastIndexOf('.') + 1);
Class staticClassWithField = loadClass(strPackage);
Class<?> staticClassWithField = loadClass(strPackage);
if (staticClassWithField != null) {
JavaTypeDefinition typeDef = getFieldType(JavaTypeDefinition.forClass(staticClassWithField),
fieldName, currentAcu.getType());