Skip to content

[java] InefficientStringBuffering/AppendCharacterWithChar: Fix false negatives with concats in appends#2591

Merged
oowekyala merged 5 commits into
pmd:masterfrom
adangel:perf-InefficientStringBuffering
Jun 21, 2020
Merged

[java] InefficientStringBuffering/AppendCharacterWithChar: Fix false negatives with concats in appends#2591
oowekyala merged 5 commits into
pmd:masterfrom
adangel:perf-InefficientStringBuffering

Conversation

@adangel

@adangel adangel commented Jun 14, 2020

Copy link
Copy Markdown
Member

Describe the PR

This originated from #1932 and merged the test cases in InefficientStringBuffering.

Example false-negative, that is fixed:

String someString = getSomeString();
StringBuilder sb = new StringBuilder();
sb.append("a" + someString + "b"); // bad - false negative
sb.append('a').append(someString).append('b'); // good

Note: This also fixes a false-negative with AppendCharacterWithChar:

StringBuilder sb = new StringBuilder(message).append("\n");

https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java#L308

Related issues

Ready?

adangel added 2 commits June 13, 2020 20:00
Originally from pmd#1932

Author: jborgers <jborgers@jpinpoint.com>
Rules affected additionally: AppendCharacterWithChar,
ConsecutiveLiteralAppends, InsufficientStringBufferDeclaration

Deprecate InefficientStringBuffering::isInStringBufferOperation
@ghost

ghost commented Jun 14, 2020

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 13 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 2 errors and 2 configuration errors.
Full report
This changeset introduces 17 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 2 errors and 2 configuration errors.
Full report
This changeset introduces 21 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 2 errors and 2 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Jun 14, 2020
…StringBuffering

Also make both rules use the rule chain.
@adangel adangel changed the title [java] Fix false negative in InefficientStringBuffering with concats in appends [java] InefficientStringBuffering/AppendCharacterWithChar: Fix false negatives with concats in appends Jun 18, 2020
@adangel adangel added a:false-negative PMD doesn't flag a problematic piece of code and removed is:WIP For PRs that are not fully ready, or issues that are actively being tackled labels Jun 18, 2020
@adangel adangel added this to the 6.25.0 milestone Jun 18, 2020
@adangel

adangel commented Jun 18, 2020

Copy link
Copy Markdown
Member Author

This one is ready now.

@oowekyala oowekyala self-assigned this Jun 18, 2020
@oowekyala oowekyala merged commit 75146a0 into pmd:master Jun 21, 2020
@adangel adangel deleted the perf-InefficientStringBuffering branch June 22, 2020 17:17
@pzygielo

Copy link
Copy Markdown
Contributor

I think the and refactor existing rules of b8e9ff1 introduced regression in AppendCharacterWithChar rule, currently open as #2881.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants