forked from phoedos/pmd
pmd: fixed #947 CloseResource rule fails if field is marked with annotation
This commit is contained in:
parent
7cbb385dbb
commit
52b8be6601
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
Fixed bug 878: False positive: UnusedFormalParameter for abstract methods
|
Fixed bug 878: False positive: UnusedFormalParameter for abstract methods
|
||||||
Fixed bug 913: SignatureDeclareThrowsException is raised twice
|
Fixed bug 913: SignatureDeclareThrowsException is raised twice
|
||||||
|
Fixed bug 947: CloseResource rule fails if field is marked with annotation
|
||||||
Fixed bug 1007: Parse Exception with annotation
|
Fixed bug 1007: Parse Exception with annotation
|
||||||
Fixed bug 1011: CloseResource Rule ignores Constructors
|
Fixed bug 1011: CloseResource Rule ignores Constructors
|
||||||
Fixed bug 1012: False positive: Useless parentheses.
|
Fixed bug 1012: False positive: Useless parentheses.
|
||||||
|
@ -97,7 +97,7 @@ public class CloseResourceRule extends AbstractJavaRule {
|
|||||||
if (ref.jjtGetChild(0) instanceof ASTClassOrInterfaceType) {
|
if (ref.jjtGetChild(0) instanceof ASTClassOrInterfaceType) {
|
||||||
ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0);
|
ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0);
|
||||||
if (types.contains(clazz.getImage())) {
|
if (types.contains(clazz.getImage())) {
|
||||||
ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) var.jjtGetChild(1).jjtGetChild(0);
|
ASTVariableDeclaratorId id = var.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ public class CloseResourceRule extends AbstractJavaRule {
|
|||||||
|
|
||||||
// if all is not well, complain
|
// if all is not well, complain
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
ASTType type = (ASTType) var.jjtGetChild(0);
|
ASTType type = var.getFirstChildOfType(ASTType.class);
|
||||||
ASTReferenceType ref = (ASTReferenceType) type.jjtGetChild(0);
|
ASTReferenceType ref = (ASTReferenceType) type.jjtGetChild(0);
|
||||||
ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0);
|
ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0);
|
||||||
addViolation(data, id, clazz.getImage());
|
addViolation(data, id, clazz.getImage());
|
||||||
|
@ -374,4 +374,35 @@ public class Test {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<test-code reinitializeRule="true">
|
||||||
|
<description>#1029 No instance level check in the close resource rule</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Test {
|
||||||
|
Connection c;
|
||||||
|
public void doIt() {
|
||||||
|
c = pool.getConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>#947 CloseResource rule fails if field is marked with annotation</description>
|
||||||
|
<expected-problems>2</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class CloseResourceRuleBug {
|
||||||
|
public void foo() {
|
||||||
|
try {
|
||||||
|
Connection c = DriverManager.getConnection("fake");
|
||||||
|
Statement s = c.createStatement();
|
||||||
|
@SuppressWarnings("PMD.CloseResource") ResultSet rs = s.executeQuery("fake");
|
||||||
|
while (rs.next()) {
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user