#1333 Error while processing Java file with Lambda expressions

This commit is contained in:
Andreas Dangel
2015-04-13 20:01:08 +02:00
parent cf22d5841b
commit 85b6b3c0ff
3 changed files with 26 additions and 1 deletions

View File

@ -373,7 +373,8 @@ public class ClassScope extends AbstractJavaScope {
Map<VariableNameDeclaration, List<NameOccurrence>> vars = s
.getDeclarations(VariableNameDeclaration.class);
for (VariableNameDeclaration d : vars.keySet()) {
if (d.getImage().equals(name.getImage())) {
// in case of simple lambda expression, the type might be unknown
if (d.getImage().equals(name.getImage()) && d.getTypeImage() != null) {
String typeName = d.getTypeImage();
typeName = qualifyTypeName(typeName);
Node declaringNode = qualifiedTypeNames.get(typeName);

View File

@ -65,6 +65,28 @@ public class ParserCornersTest extends ParserTst {
parseJava18(test18);
}
/**
* Test for https://sourceforge.net/p/pmd/bugs/1333/
*/
@Test
public void testLambdaBug1333() {
parseJava18("final class Bug1333 {\n" +
" private static final Logger LOG = LoggerFactory.getLogger(Foo.class);\n" +
"\n" +
" public void deleteDirectoriesByNamePattern() {\n" +
" delete(path -> deleteDirectory(path));\n" +
" }\n" +
"\n" +
" private void delete(Consumer<? super String> consumer) {\n" +
" LOG.debug(consumer.toString());\n" +
" }\n" +
"\n" +
" private void deleteDirectory(String path) {\n" +
" LOG.debug(path);\n" +
" }\n" +
"}");
}
@Test
public void testMultipleExceptionCatching() {
String code = "public class Foo { public void bar() { "