You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When reducing the expression to compute the size, the rule fails to process non-constant conditions. But in doing so, misses that some branches may effectively allocate too small a buffer.
Ideally, these expressions would be reduced to retrieve the minimum possible value to analyze, as the rule checks against the minimum number of appended chars expected.
Code Sample demonstrating the issue:
publicclassConditionalExpression {
publicvoidbar(intarg) {
StringBuffersb = newStringBuffer(arg > 1 ? 500 : 2); // Should report a warning at this line, 2 is too smallsb.append('a');
sb.append('a');
sb.append('a');
}
}
Expected outcome:
PMD should report a violation at line 3, but doesn't. This is a false-negative.
Running PMD through:[CLI | Ant | Maven | Gradle | Designer | Other]
Any
The text was updated successfully, but these errors were encountered:
Affects PMD Version:
7.0.0
Rule:
InsufficientStringBufferDeclaration
Description:
When reducing the expression to compute the size, the rule fails to process non-constant conditions. But in doing so, misses that some branches may effectively allocate too small a buffer.
Ideally, these expressions would be reduced to retrieve the minimum possible value to analyze, as the rule checks against the minimum number of appended chars expected.
Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 3, but doesn't. This is a false-negative.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Any
The text was updated successfully, but these errors were encountered: