From 32bf09ffd7c8feebc1caa733fa81c1896f02f800 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Wed, 16 Oct 2013 20:43:26 +0200 Subject: [PATCH] pmd: fix #1135 CheckResultSet ignores results set declared outside of try/catch --- pmd/etc/changelog.txt | 1 + .../java/rule/basic/CheckResultSetRule.java | 4 +- .../java/rule/basic/xml/CheckResultSet.xml | 67 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index c4fabc8c50..0b2398e7a2 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -8,6 +8,7 @@ Fixed bug 1121: NullPointerException when invoking XPathCLI Fixed bug 1130: CloseResource doesn't recognize custom close method Fixed bug 1131: CloseResource should complain if code betwen declaration of resource and try Fixed bug 1134: UseStringBufferLength: false positives +Fixed bug 1135: CheckResultSet ignores results set declared outside of try/catch Fixed bug 1136: ECMAScript: NullPointerException in getLeft() and getRight() Fixed bug 1141: ECMAScript: getFinallyBlock() is buggy. Fixed bug 1142: ECMAScript: getCatchClause() is buggy. diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckResultSetRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckResultSetRule.java index 7dc925cbd5..827ab58e0c 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckResultSetRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckResultSetRule.java @@ -45,8 +45,8 @@ public class CheckResultSetRule extends AbstractJavaRule { ASTVariableDeclarator declarator = node.getFirstChildOfType(ASTVariableDeclarator.class); if (declarator != null) { ASTName name = declarator.getFirstDescendantOfType(ASTName.class); - if (name != null && name.getImage().endsWith("executeQuery")) { - + if (type.getType() != null + || (type.getType() == null && name != null && name.getImage().endsWith("executeQuery"))) { ASTVariableDeclaratorId id = declarator.getFirstChildOfType(ASTVariableDeclaratorId.class); resultSetVariables.put(id.getImage(), node); } diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/CheckResultSet.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/CheckResultSet.xml index 2e5a84fabe..c88ebf6b2c 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/CheckResultSet.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/CheckResultSet.xml @@ -158,6 +158,73 @@ public class Test { return _count; } +} + ]]> + + + + #1135 CheckResultSet ignores results set declared outside of try/catch (good case) + 0 + + + + + #1135 CheckResultSet ignores results set declared outside of try/catch + 1 + + + + + #1135 CheckResultSet ignores results set declared outside of try/catch - prevent false positive + 0 +