Merge pull request #3347 from adangel:issue-3340-guardlogstatement

[java] NullPointerException applying rule GuardLogStatement #3347
This commit is contained in:
Andreas Dangel
2021-06-24 14:42:53 +02:00
3 changed files with 16 additions and 1 deletions

View File

@ -68,6 +68,7 @@ PMD will now ignore:
* [#3114](https://github.com/pmd/pmd/issues/3114): \[java] UnusedAssignment false positive when reporting unused variables
* [#3315](https://github.com/pmd/pmd/issues/3315): \[java] LiteralsFirstInComparisons false positive with two constants
* [#3341](https://github.com/pmd/pmd/issues/3341): \[java] JUnitTestsShouldIncludeAssert should support Junit 5
* [#3340](https://github.com/pmd/pmd/issues/3340): \[java] NullPointerException applying rule GuardLogStatement
* java-codestyle
* [#3317](https://github.com/pmd/pmd/pull/3317): \[java] Update UnnecessaryImport to recognize usage of imported types in javadoc's `@exception` tag
* java-errorprone

View File

@ -203,7 +203,7 @@ public class GuardLogStatementRule extends AbstractJavaRule implements Rule {
}
private boolean hasArgumentWithMethodCall(ASTPrimarySuffix node) {
if (!node.isArguments()) {
if (!node.isArguments() || node.getArgumentCount() <= 0) {
return false;
}

View File

@ -538,6 +538,20 @@ public class Logger {
});
runTestLambda((s1, s2) -> {LOGGER.debug(s1 + s2);});
}
}
]]></code>
</test-code>
<test-code>
<description>NullPointerException applying rule GuardLogStatement (#3340)</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Logger {
private static final Logger LOGGER = new Logger();
public void bar() {
LOGGER.debug();
}
}
]]></code>
</test-code>