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 positive for initial calculated StringBuilder size · Issue #1438 · pmd/pmd

[java] InsufficientStringBufferDeclaration false positive for initial calculated StringBuilder size #1438

New issue
Copy link
New issue
Copy link
Closed
#3277
Closed
[java] InsufficientStringBufferDeclaration false positive for initial calculated StringBuilder size#1438
#3277
Copy link
Assignees
adangel
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.35.0

Description

@vbrandl
vbrandl
opened on Nov 6, 2018
Issue body actions

Affects PMD Version:

  • 6.9.0
  • 5.8.1

Rule:

InsufficientStringBufferDeclaration

Description:

When calculating the size of a StringBuilder at runtime, e.g. by adding the lengths of strings to be appended or by adding constant values e.g. for the output of Date/DecimalFormat will result in a InsufficientStringBufferDeclaration even if the calculated value will be larger than the length of the constant strings alone.

Code Sample demonstrating the issue:

public String foo(final String x, final String y, final double z, final Date d, final double v) {
	final StringBuilder sb = new StringBuilder(20 + 9*2 + 16 + 2 * x.length() + y.length());
	final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
	df.applyPattern("#,##0.000");
	final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy hh:mm");
	sb.append("foobar")
		.append(df.format(z))
		.append(' ')
		.append(x)
		.append(y)
		.append("foobar")
		.append(sdf.format(d))
		.append("foobar")
		.append(df.format(v))
		.append(' ')
		.append(x);
	return sb.toString();
}

Running PMD through: Gradle

Activity

  1. jsotuyod
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Nov 7, 2018
  2. adangel
    changed the title [-][Java] False positive for initial StringBuilder size[/-] [+][java] False positive for initial StringBuilder size[/+] on Nov 7, 2018
  3. adangel
    changed the title [-][java] False positive for initial StringBuilder size[/-] [+][java] InsufficientStringBufferDeclaration false positive for initial calculated StringBuilder size[/+] on May 14, 2021
  4. adangel
    self-assigned this
    on May 14, 2021
  5. adangel
    added a commit that references this issue on May 14, 2021

    [java] InsufficientStringBufferDeclaration fix FP (pmd#1438)

    899f80d
  6. adangel
    added this to the 6.35.0 milestone on May 14, 2021
  7. oowekyala
    closed this as completedin 899f80don May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

    Milestone

    • 6.35.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.