Skip to content

[java] Fix #6237: Deprecate AddEmptyString without replacement - #7311

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
amritkang165:deprecate-6327-add-empty-string
Nov 11, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
amritkang165:deprecate-6327-add-empty-string

Conversation

@amritkang165

@amritkang165 amritkang165 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Describe the PR

AddEmptyString recommends replacing empty-string concatenation for performance reasons, but that advice no longer holds on modern JDKs. This deprecates the rule without a replacement in PMD 7.30.0, for removal in PMD 8.0.0, following the direction in the issue.

Explicit rule references continue to work during the deprecation period, while references to the whole Performance category exclude it. The patch updates the rule description, examples, Java deprecation annotation, and release notes, and adjusts an existing warning snapshot for the XML line-number change. Existing ruleset-loading tests cover deprecation behavior; the rule's eight XML test cases remain unchanged.

Validation: all 121 selected tests passed (AddEmptyStringTest, core and Java RuleSetFactoryTest, and QuickstartRulesetTest). Checkstyle and git diff --check passed. The full ./mvnw clean verify build was not run locally.

Related issues

Ready?

  • Added unit tests for fixed bug/feature (existing coverage retained; redundant additions removed following review)
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@amritkang165
amritkang165 force-pushed the deprecate-6327-add-empty-string branch from 6560cca to 08d91ca Compare November 10, 2026 12:08
@UncleOwen UncleOwen changed the title [java] Deprecate AddEmptyString without replacement [java] Fix #6237: Deprecate AddEmptyString without replacement Nov 10, 2026
@pmd-actions-helper

pmd-actions-helper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 3216 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-11-10 22:49:11+00:00 for fce9a57)

Comment on lines +19 to +40

@Test
void explicitReferenceStillLoadsDeprecatedRule() {
Rule rule = new RuleSetLoader().warnDeprecated(false)
.loadFromResource("category/java/performance.xml/AddEmptyString")
.getRuleByName("AddEmptyString");

assertNotNull(rule);
assertTrue(rule.isDeprecated());
}

@Test
void categoryReferenceExcludesDeprecatedRule() {
RuleSet rules = new RuleSetLoader().loadFromString("ruleset.xml",
"<ruleset name=\"test\">"
+ "<description>Performance rules</description>"
+ "<rule ref=\"category/java/performance.xml\"/>"
+ "</ruleset>");

assertNull(rules.getRuleByName("AddEmptyString"));
assertNotNull(rules.getRuleByName("AppendCharacterWithChar"));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have tests that verify that a a deprecated rule isn't loaded when a whole category is included. See https://github.com/pmd/pmd/blob/main/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/RuleSetFactoryTest.java#L809

Please remove this, it's just one more thing to forget when we remove the rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the duplicate test and unused imports in 2cfc635. Tests and Checkstyle pass. Thanks for pointing this out!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should apply to both tests, you can remove the second one too (most deprecated rules have just the .xml based tests).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the second test too in fce9a57. The existing XML tests are unchanged, and all 121 selected tests and Checkstyle pass. Thanks

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@UncleOwen UncleOwen added this to the 7.30.0 milestone Nov 11, 2026
@UncleOwen
UncleOwen merged commit 84ed9dc into pmd:main Nov 11, 2026
13 checks passed
@adangel adangel added the is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] AddEmptyString: Deprecate rule because performance claim is not valid anymore

4 participants