forked from phoedos/pmd
Merge branch 'pr-1551'
This commit is contained in:
@ -50,9 +50,10 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#1517](https://github.com/pmd/pmd/issues/1517): \[java] New Rule: UseDiamondOperator
|
||||
* java-errorprone
|
||||
* [#1035](https://github.com/pmd/pmd/issues/1035): \[java] ReturnFromFinallyBlock: False positive on lambda expression in finally block
|
||||
* [#1549](https://github.com/pmd/pmd/issues/1549): \[java] NPE in PMD 6.8.0 InvalidSlf4jMessageFormat
|
||||
* plsql
|
||||
* [#1507](https://github.com/pmd/pmd/issues/1507): \[plsql] Parse Exception when using '||' operator in where clause
|
||||
* [#1508](https://github.com/pmd/pmd/issues/1508): \[plsql] Parse Exception when using SELECT COUNT(*)
|
||||
* [#1508](https://github.com/pmd/pmd/issues/1508): \[plsql] Parse Exception when using SELECT COUNT(\*)
|
||||
* [#1509](https://github.com/pmd/pmd/issues/1509): \[plsql] Parse Exception with OUTER/INNER Joins
|
||||
* [#1511](https://github.com/pmd/pmd/issues/1511): \[plsql] Parse Exception with IS NOT NULL
|
||||
|
||||
@ -68,6 +69,7 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#1530](https://github.com/pmd/pmd/pull/1530): \[java] New rule: AvoidReassigningLoopVariables - [Kris Scheibe](https://github.com/kris-scheibe)
|
||||
* [#1534](https://github.com/pmd/pmd/pull/1534): \[java] This is the change regarding the usediamondoperator #1517 - [hemanshu070](https://github.com/hemanshu070)
|
||||
* [#1545](https://github.com/pmd/pmd/pull/1545): \[doc] fixing dead links + tool to check for dead links automatically - [Kris Scheibe](https://github.com/kris-scheibe)
|
||||
* [#1551](https://github.com/pmd/pmd/pull/1551): \[java] InvalidSlf4jMessageFormatRule should not throw NPE for enums - [Robbie Martinus](https://github.com/rmartinus)
|
||||
|
||||
{% endtocmaker %}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEnumBody;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
|
||||
@ -175,7 +176,7 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
|
||||
if (count == 0) {
|
||||
// look if the message is defined in a field
|
||||
final List<ASTFieldDeclaration> fieldlist = node.getFirstParentOfType(ASTClassOrInterfaceBody.class)
|
||||
final List<ASTFieldDeclaration> fieldlist = node.getFirstParentOfAnyType(ASTClassOrInterfaceBody.class, ASTEnumBody.class)
|
||||
.findDescendantsOfType(ASTFieldDeclaration.class);
|
||||
// only look for ASTVariableDeclarator that are Fields
|
||||
final List<ASTVariableDeclarator> fields = new ArrayList<>(fieldlist.size());
|
||||
|
@ -335,4 +335,49 @@ public final class Main {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>NPE in enums (see #1549)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public enum LoggerHelper {
|
||||
INSTANCE;
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(LoggerHelper.class);
|
||||
|
||||
public void sendMessage(String message) {
|
||||
log.info(message);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LoggerHelper.INSTANCE.sendMessage("A message");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>missing argument in enum</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>12</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public enum LoggerHelper {
|
||||
INSTANCE;
|
||||
|
||||
private static final String pattern = "log: {}";
|
||||
|
||||
public static void main(String[] args) {
|
||||
final Logger logger = LoggerFactory.getLogger(LoggerHelper.class);
|
||||
|
||||
logger.info(pattern, 1, 2);
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
Reference in New Issue
Block a user