Affects PMD Version:6.40.0
Rule: UseStringBufferLength
Description:
I think PMD should have reported a violation at line 4, but it doesn't. This code sample can reduce the performance, so I think it is a false negative. We should consider constant String for this rule. 🤔
Code Sample demonstrating the issue:
public void foo() { StringBuffer sb = new StringBuffer("any_string"); final String nullStr = ""; if (sb.toString().equals(nullStr)) { // PMD should report a warning here System.out.println("Buffer is empty"); } // the preferred way if (sb.length() == 0) { System.out.println("Buffer is empty"); } }
Expected outcome:A warning
PMD should report a violation at line 4, but doesn't. This is a false-negative.
Running PMD through: [Maven]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4