This rule is defined by the following XPath expression:
//Type/ReferenceType/ClassOrInterfaceType[ (@Image = 'ResultSet') and (../../../descendant::Name[ends-with(@Image,'executeQuery')]) and ( (not (contains( (./ancestor::Block/descendant::WhileStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.next') ) ) ) and ( not ( contains( (./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.next') ) ) ) and (not (contains( (./ancestor::Block/descendant::WhileStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.previous') ) ) ) and ( not ( contains( (./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.previous') ) ) ) and ( not ( contains( (./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.last') ) ) ) and ( not ( contains( (./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image), concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.first') ) ) ) ) ]
Example:
[ // This is NOT appropriate ! Statement stat = conn.createStatement(); ResultSet rst = stat.executeQuery("SELECT name FROM person"); rst.next(); // what if it returns a 'false' ? String firstName = rst.getString(1); // This is appropriate... Statement stat = conn.createStatement(); ResultSet rst = stat.executeQuery("SELECT name FROM person"); if (rst.next()) { String firstName = rst.getString(1); } else { // here you deal with the error ( at least log it) }