PMD CheckResultSet gives false positive in a do/while loop
A source code analyzer
Brought to you by:
adangel,
juansotuyo
The following code gives a CheckResultSet Error, when it is being checked correctly in both the outer if
and the while
ResultSet results = null;
String answer;
List<String> stringList = new ArrayList<String>();
//check the result set. Yes, this moves the cursor to the first position
if (results.first()) {
//do a little logic
do {
//this is handeling paging
if (results.getInt("RowNum") >= firstEntry && results.getInt("RowNum") <= lastEntry) {
answer = results.getString("answer");
stringList.add(answer);
} else {
results.last();
}
} while(results.next()); //advance the cursor to the next position
}
Unfortunately your code example doesn't trigger the rule (anymore?).
On which line did you get the violation report?
We have refactored the code that contained this issue and are no longer getting a false positive. Since i am unable to replicate it elsewhere, it can be marked as closed
Thanks for the feedback.