Skip to content

[java] Fix #3124: Deprecate statementOrderMatters property of VariableCanBeInlined - #7065

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
fudianchn:deprecate-variablecanbeinlined-statementordermatters
Sep 13, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
fudianchn:deprecate-variablecanbeinlined-statementordermatters

Conversation

@fudianchn

@fudianchn fudianchn commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.

Describe the PR

statementOrderMatters=false relaxes VariableCanBeInlined to report any variable used solely in a return/throw statement, assuming the statements between the declaration and the return have no side effects. The assumption is unsafe: following the suggestion can introduce an application bug. This is what #3124 asks to remove.

The property came from the deprecated UnnecessaryLocalBeforeReturn rule: it was carried over when VariableCanBeInlined was created in #5847 and was not discussed in that review.

This PR marks it deprecated via DEPRECATED_RULE_PROPERTY_MARKER (same mechanism as MethodNamingConventions):

  • configuring it logs a warning at ruleset load,
  • the rule documentation displays a deprecated label.

Behavior is unchanged: the default stays statementOrderMatters=true. The property can be removed later.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Regression

No rule behavior change: the property default and the rule logic are untouched, only the property description changed — expect zero new violations in the regression tester. The four statementOrderMatters=false test cases in the rule's test XML still pass and now log the deprecation warning on stderr, which is the intended new behavior.

…ableCanBeInlined

The property silently migrated into the replacement rule when
UnnecessaryLocalBeforeReturn was deprecated (pmd#5847): setting it to false
relaxes the rule under the assumption that the statements between the
declaration and the return/throw have no side effects, which is unsafe
and could introduce an application bug when following the suggestion.

Mark the property as deprecated using DEPRECATED_RULE_PROPERTY_MARKER:
configuring it now issues a warning when the ruleset is loaded, and the
rule documentation displays a deprecated label. Behavior is unchanged
while deprecated (the conservative default, statementOrderMatters=true,
stays the default); the property will be removed later.

Signed-off-by: 付典 <[email protected]>
@fudianchn fudianchn changed the title [java] Fix #3124: Deprecate statementOrderMatters property of VariableCanBeInlined [java] Deprecate statementOrderMatters property of VariableCanBeInlined (refs #3124) Sep 12, 2026
@pmd-actions-helper

pmd-actions-helper Bot commented Sep 12, 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 0 violations, 16 errors and 9 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-09-13 18:35:18+00:00 for 5eb3435)

@UncleOwen UncleOwen added this to the 7.28.0 milestone Sep 13, 2026

@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 merged commit 6c8bbe8 into pmd:main Sep 13, 2026
13 checks passed
@adangel adangel changed the title [java] Deprecate statementOrderMatters property of VariableCanBeInlined (refs #3124) [java] Fix #3124: Deprecate statementOrderMatters property of VariableCanBeInlined Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] UnnecessaryLocalBeforeReturn/VariableCanBeInlined: deprecate property statementOrderMatters

2 participants