Menu

#1199 PMD CheckResultSet gives false positive in a do/while loop

PMD-5.1.3
not-reproducible
None
PMD
3-Major
Bug
5.1.1
2014-08-31
2014-05-12
No

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
}

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-08-09

    Unfortunately your code example doesn't trigger the rule (anymore?).
    On which line did you get the violation report?

     
  • Andreas Dangel

    Andreas Dangel - 2014-08-09
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-next
     
  • michael beaumont

    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

     
  • Andreas Dangel

    Andreas Dangel - 2014-08-21

    Thanks for the feedback.

     
  • Andreas Dangel

    Andreas Dangel - 2014-08-21
    • status: more-info-needed --> not-reproducible
     

Log in to post a comment.

MongoDB Logo MongoDB