![JAR search and dependency download from the Maven repository](/logo.png)
resources.report.rules.pmd.CheckResultSet.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
CheckResultSet
CheckResultSet
Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet. Indeed,
if the value return is 'false', the developer should deal with it !
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)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy