Menu

#445 False+: UseIndexOfChar

closed
5
2012-10-07
2006-02-17
m.hilpert
No

I get several

String.indexOf(char) is faster than String.indexOf
(String)

warnings for code like this:

index = result.indexOf("{"+pkey.trim()+"?", index);

It seems that the subsequent string concatenation is
not taken into account. Should check for a
trailing '+' sign.

Discussion

  • Tom Copeland

    Tom Copeland - 2006-02-18

    Logged In: YES
    user_id=5159

    Right you are, thanks for the report! Here's a
    representative snippet:

    ==================
    public class Bar {
    void foo(String result) {
    int index = result.indexOf("{" + bar, index);
    }
    }
    ==================

    Assigning this back to me since I wrote this rule...

    Thanks for the report,

    Tom
    http://pmdapplied.com/

     
  • Tom Copeland

    Tom Copeland - 2006-02-18

    Logged In: YES
    user_id=5159

    Fixed in CVS, and you can download a new pmd-3.5.jar file here:

    http://infoether.com/~tom/pmd-3.5.jar

    that contains that fix.

    Thanks for the report,

    Tom
    Using PMD? Get the book! http://pmdapplied.com/

     

Log in to post a comment.

MongoDB Logo MongoDB