Fix NullPointerException in ClassScope.qualifyTypeName()

This commit is contained in:
Björn Kautler
2015-04-14 11:07:20 +02:00
parent e8c36b34f8
commit f310138f9d
2 changed files with 14 additions and 0 deletions

View File

@ -307,6 +307,9 @@ public class ClassScope extends AbstractJavaScope {
}
private String qualifyTypeName(String typeImage) {
if (typeImage == null) {
return null;
}
for (String qualified : this.getEnclosingScope(SourceFileScope.class).getQualifiedTypeNames().keySet()) {
int fullLength = qualified.length();
int nameLength = typeImage.length();

View File

@ -269,6 +269,11 @@ public class ClassScopeTest extends STBBaseTst {
}
@Test
public void testNullType() {
parseCode(TEST_NULL_TYPE);
}
private static final String NESTED_CLASS_FIELD_AND_PARAM =
"public class Foo {" + PMD.EOL +
" class Test {" + PMD.EOL +
@ -376,6 +381,12 @@ public class ClassScopeTest extends STBBaseTst {
" }" + PMD.EOL +
"}";
public static final String TEST_NULL_TYPE =
"public abstract class NullTypeTest {" + PMD.EOL +
" protected Comparator<TreeNode> nodesComparator = (o1, o2) -> StringHelper.saveCompare(getFilterableString(o1), getFilterableString(o2));" + PMD.EOL +
" public abstract String getFilterableString(TreeNode node);" + PMD.EOL +
"}";
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(ClassScopeTest.class);
}