Repository navigation
[java] Fix #6237: Deprecate AddEmptyString without replacement - #7311
Conversation
6560cca to
08d91ca
Compare
|
Compared to main: (comment created at 2026-11-10 22:49:11+00:00 for fce9a57) |
|
|
||
| @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")); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Removed the duplicate test and unused imports in 2cfc635. Tests and Checkstyle pass. Thanks for pointing this out!
There was a problem hiding this comment.
I think this should apply to both tests, you can remove the second one too (most deprecated rules have just the .xml based tests).
There was a problem hiding this comment.
Removed the second test too in fce9a57. The existing XML tests are unchanged, and all 121 selected tests and Checkstyle pass. Thanks
Describe the PR
AddEmptyStringrecommends 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 JavaRuleSetFactoryTest, andQuickstartRulesetTest). Checkstyle andgit diff --checkpassed. The full./mvnw clean verifybuild was not run locally.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)