#1263 PMD reports CheckResultSet violation in completely unrelated source files.
This commit is contained in:
+8
-1
@@ -12,6 +12,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTIfStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
|
||||
@@ -35,7 +36,13 @@ public class CheckResultSetRule extends AbstractJavaRule {
|
||||
methods.add(".last");
|
||||
methods.add(".first");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
resultSetVariables.clear();
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTLocalVariableDeclaration node, Object data) {
|
||||
ASTClassOrInterfaceType type = node.getFirstChildOfType(ASTType.class).getFirstDescendantOfType(ASTClassOrInterfaceType.class);
|
||||
|
||||
+21
@@ -284,6 +284,27 @@ public class Foo {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1263 PMD reports CheckResultSet violation in completely unrelated source files.</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class Foo {
|
||||
public void firstMethod() {
|
||||
ResultSet results = stmt.executeQuery();
|
||||
if (results.next()) {
|
||||
// do something
|
||||
}
|
||||
}
|
||||
|
||||
public void secondMethod() {
|
||||
MyIterator results = getMyResultsIterator();
|
||||
results.next();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
Reference in New Issue
Block a user