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
+