forked from phoedos/pmd
Fix #4505
This commit is contained in:
@ -36,6 +36,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTConstructorCall;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTContinueStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTDoStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEnumConstant;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldAccess;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
@ -954,6 +955,7 @@ public final class DataflowPass {
|
||||
|
||||
@Override
|
||||
public SpanInfo visitTypeDecl(ASTAnyTypeDeclaration node, SpanInfo data) {
|
||||
// process initializers and ctors first
|
||||
processInitializers(node.getDeclarations(), data, node.getSymbol());
|
||||
|
||||
for (ASTBodyDeclaration decl : node.getDeclarations()) {
|
||||
@ -989,12 +991,14 @@ public final class DataflowPass {
|
||||
|
||||
for (ASTBodyDeclaration declaration : declarations) {
|
||||
final boolean isStatic;
|
||||
if (declaration instanceof ASTFieldDeclaration) {
|
||||
if (declaration instanceof ASTEnumConstant) {
|
||||
isStatic = true;
|
||||
} else if (declaration instanceof ASTFieldDeclaration) {
|
||||
isStatic = ((ASTFieldDeclaration) declaration).isStatic();
|
||||
} else if (declaration instanceof ASTInitializer) {
|
||||
isStatic = ((ASTInitializer) declaration).isStatic();
|
||||
} else if (declaration instanceof ASTConstructorDeclaration
|
||||
|| declaration instanceof ASTCompactConstructorDeclaration) {
|
||||
|| declaration instanceof ASTCompactConstructorDeclaration) {
|
||||
ctors.add(declaration);
|
||||
continue;
|
||||
} else {
|
||||
|
@ -400,4 +400,25 @@ record MyRecord(boolean b) {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>NPE with Switch in enum constant body</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>7</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
enum Foo {
|
||||
A {
|
||||
void foo() {
|
||||
switch (A) {
|
||||
case A:
|
||||
if (A != null) {}
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user