Menu

#1360 False positive UC_USELESS_CONDITION if local variable index equals to the numeric value

3.0.1
closed-invalid
5
2015-02-17
2015-02-17
No

The local variable c has local index 13 in bytecode, which equals to the '\r' value.
Findbugs reports:

Rank: Of Concern (16), confidence: Normal
Pattern: UC_USELESS_CONDITION
Type: UC, Category: STYLE (Dodgy code)

             for (int i = 0; i < line.length(); i++) {
                 char c = line.charAt(i);
                 if (c == ',') {
                     if (inQuote) {
                         // normal character
                         currentStrBf.append(c);
                     } else {
                         lineList.add(currentStrBf.toString());
                         currentStrBf.setLength(0);
                     }
                 } else if(c == '"') {
                     int j = i + 1;
                     if ('"' == line.charAt(j)) {
                         // escape character
                         currentStrBf.append(line.charAt(j));
                         i = j;
                     } else {
                        // the enclosed character
                         inQuote = !inQuote;
                     }
                 } else if(c != '\n' || c != '\r') { // UC_USELESS_CONDITION!
                     // normal character
                     currentStrBf.append(c);
                 }
             }

Discussion

  • Tagir Valeev

    Tagir Valeev - 2015-02-17
    • status: open --> open-invalid
     
  • Tagir Valeev

    Tagir Valeev - 2015-02-17

    It's a bug in your code. If c != '\n', the second condition is not checked. If c == '\n', then it's definitely not equal to '\r'. Seems that && was intended instead of ||.

     
  • Andrey Loskutov

    Andrey Loskutov - 2015-02-17

    The simplest explanation is the right one :-)

     
  • Andrey Loskutov

    Andrey Loskutov - 2015-02-17
    • status: open-invalid --> closed-invalid
    • Priority: 1 --> 5
     

Log in to post a comment.