A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3845 below:

[java] InsufficientStringBufferDeclaration should consider literal expression · Issue #3845 · pmd/pmd · GitHub

Affects PMD Version:6.42.0

Rule:InsufficientStringBufferDeclaration

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_performance.html#insufficientstringbufferdeclaration

Description:
Hi, I found a false negative in the following case. At line 3, PMD should have reported a warning because the length of StringBuffer is 2, but it is insufficient to store characters. Besides, PMD can report the warning at line 2. So, I think this is a false negative.

Code Sample demonstrating the issue:

public void bar() {
//        StringBuffer sb = new StringBuffer(2); // This line can be detected
        StringBuffer sb = new StringBuffer(1 + 2 - 1);  // Should report a warning at this line
        sb.append('a');
        sb.append('a');
        sb.append('a');
    }

Expected outcome: A Warning

PMD should report a violation at line 3, 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