GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] InsufficientStringBufferDeclaration: False negatives with String constants · Issue #3857 · pmd/pmd

[java] InsufficientStringBufferDeclaration: False negatives with String constants #3857

New issue
Copy link
New issue
Copy link
Closed
#6366
Closed
[java] InsufficientStringBufferDeclaration: False negatives with String constants#3857
#6366
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.21.0

Description

@MetaBF
MetaBF
opened on Mar 18, 2022
Issue body actions

Affects PMD Version:
7.0.0

Rule: InsufficientStringBufferDeclaration
https://pmd.github.io/latest/pmd_rules_java_performance.html#insufficientstringbufferdeclaration

Description:

Rule InsufficientStringBufferDeclaration is supposed to prevent unnecessary resizing. In this case, the size of the constant String PRE is 21 (at point 1). PRE is then appended to local variable builder (at point 3), a StringBuilder instance initialized with default capacity 16 (at point 2).

Hence PMD should report a violation at line 10 (at point 2).

Code Sample demonstrating the issue:

import java.util.ArrayList;
import java.util.List;

public class Example {
    public List<String> list = new ArrayList<>();

    public static final String PRE = "The size of list is: "; // point 1: 21 characters, exceed default 16 

    public void func() {
        StringBuilder builder = new StringBuilder(); // point 2: improper initial capacity, false negative
        builder.append(PRE); // point 3
    }
}

Expected outcome:

PMD should report a violation at line 10, but doesn't. This is a false-negative.

Running PMD through: [CLI]

Activity

  1. MetaBF
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Mar 18, 2022
  2. jsotuyod
    added
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    on Mar 17, 2024
  3. jsotuyod
    removed
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    on Mar 25, 2024
  4. adangel
    changed the title [-][java] InsufficientStringBufferDeclaration should consider constant String. [/-] [+][java] InsufficientStringBufferDeclaration: False negatives with constant Strings[/+] on Jan 23, 2026
  5. adangel
    changed the title [-][java] InsufficientStringBufferDeclaration: False negatives with constant Strings[/-] [+][java] InsufficientStringBufferDeclaration: False negatives with String constants[/+] on Jan 23, 2026
  6. adangel
    added a commit that references this issue on Jan 23, 2026

    [doc] Update release notes (pmd#3857, pmd#6366)

    cbea34b
  7. adangel
    added this to the 7.21.0 milestone on Jan 23, 2026
  8. adangel
    closed this as completedin 9db4b18on Jan 23, 2026
  9. adangel
    added a commit that references this issue on Jan 23, 2026

    [java] Fix pmd#3857: InsufficientStringBufferDeclaration should consi…

    This issue will close once commit 9db4b18 is merged into the 'main' branch.
    9db4b18
  10. wener-tiobe
    added a commit that references this issue on Feb 10, 2026

    RM-37163: CPD 7.21.0 upgrade (#8)

    6a1959a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.21.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.