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] Fix #5770: New Rule: VariableCanBeInlined by Pankraz76 · Pull Request #5847 · pmd/pmd

Conversation

@Pankraz76

@Pankraz76 Pankraz76 commented Jun 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule

evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule.

Related issues

  • Fix [java] New Rule: VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown #5770
  • Old PR: Fix #5770: [java] UnnecessaryLocalBeforeBranchRule #5835

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from c8bfc98 to fa07c3c Compare June 23, 2025 12:24
@Pankraz76 Pankraz76 mentioned this pull request Jun 23, 2025
Fix #5770: [java] UnnecessaryLocalBeforeBranchRule #5835
Closed
4 tasks done
@Pankraz76
Pankraz76 marked this pull request as ready for review June 23, 2025 12:32
@github-actions

github-actions Bot commented Jun 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 185 new violations, 0 new errors and 0 new configuration errors,
removes 153 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-08-08 10:06:18+00:00 for d5e111a)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from fa07c3c to df87f06 Compare June 23, 2025 20:22
adangel
adangel reviewed Jun 29, 2025
View reviewed changes
Comment thread ...a/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryLocalBeforeRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel reviewed Jun 29, 2025
View reviewed changes
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel reviewed Jun 29, 2025
View reviewed changes
Comment thread pmd-java/src/main/resources/rulesets/java/quickstart.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76 Pankraz76 changed the title Fix #5770: [java] UnnecessaryLocalBeforeRule Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule Jun 29, 2025
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from e3fd927 to e6f5266 Compare June 29, 2025 11:10
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule Jun 29, 2025
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from cf0e12e to 6d31e91 Compare June 29, 2025 11:12
@Pankraz76
Pankraz76 requested a review from adangel June 29, 2025 11:12
Pankraz76
Pankraz76 commented Jun 29, 2025
View reviewed changes
Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala

oowekyala commented Jun 29, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I think the new name is too specific because this rule could as well apply to yield statements. I think the best applicable names would be UnnecessaryLocalBeforeBranch or UnnecessaryLocalBeforeJump

Or even BeforeControlFlowTransfer if you think those are too obscure. I would think people know what a jump is though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76

Pankraz76 commented Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

I think the new name is too specific because this rule could as well apply to yield statements. I think the best applicable names would be UnnecessaryLocalBeforeBranch or UnnecessaryLocalBeforeJump

Or even BeforeControlFlowTransfer if you think those are too obscure. I would think people know what a jump is though.

thanks for the yield case.

Yes then might use Branch, as its known from test coverage tools too, also this was the initial suggestion.

Branch is generic and known in the dev context.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76 Pankraz76 changed the title Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeBranch Jun 30, 2025
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from e703fd7 to 7538251 Compare June 30, 2025 11:44
@adangel

adangel commented Jul 8, 2025

Copy link
Copy Markdown
Member

Let's first fix specification before continuing on the pull request, so that we know, what to do: #5770

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76 Pankraz76 mentioned this pull request Jul 14, 2025
[java] Fix #5837: New Rule: OverrideBothEqualsAndHashCodeOnComparable #5856
Merged
4 tasks done
@adangel adangel mentioned this pull request Jul 18, 2025
[java] New Rule: VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown #5770
Closed
@Pankraz76
Pankraz76 marked this pull request as draft July 20, 2025 16:40
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from d5111fa to c9a957b Compare August 8, 2025 09:02
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeBranch Fix #5770: [java] migrate UnnecessaryLocalBeforeReturnRule and UnnecessaryLocalBeforeBranch into VariableCanBeInlined Aug 8, 2025
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] migrate UnnecessaryLocalBeforeReturnRule and UnnecessaryLocalBeforeBranch into VariableCanBeInlined Fix #5770: [java] VariableCanBeInlined Aug 8, 2025
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from c9a957b to de5e6d5 Compare August 8, 2025 09:24
@Pankraz76

Pankraz76 commented Aug 8, 2025

Copy link
Copy Markdown
Contributor Author

check issue:

again broken window effect still not closed.

[INFO] There are 2 errors reported by Checkstyle 10.26.1 with /net/sourceforge/pmd/pmd-checkstyle-config.xml ruleset.
[ERROR] src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/VariableCanBeInlinedRule.java:[1] (header) RegexpHeader: Line does not match expected header line of '^/*$'.
[ERROR] src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/VariableCanBeInlinedTest.java:[1] (header) RegexpHeader: Line does not match expected header line of '^/*$'.
[INFO] ------------------------------------------------------------------------

  • unite BSD-style license by automation #5850
  • Fix #5845: [java] align BSD-style license by automation #5845
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76
Pankraz76 marked this pull request as ready for review August 8, 2025 09:46
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from 422d5aa to d5e111a Compare August 8, 2025 09:49
@adangel adangel changed the title Fix #5770: [java] VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 11, 2025
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Aug 11, 2025
adangel
adangel requested changes Aug 11, 2025
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the updated PR!

Unfortunately, it is not ready yet, but almost! Can you please have a look?

And don't worry about the release notes, I'll update it once the PR is ready to be merged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Pankraz76 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryLocalBeforeReturnRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pmd-actions-helper

pmd-actions-helper Bot commented Aug 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 185 new violations, 0 new errors and 0 new configuration errors,
removes 153 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-08-15 09:46:47+00:00 for a2eb2e4)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76
Fix pmd#5770: [java] New Rule: VariableCanBeInlined
728d0e4
@Pankraz76
Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from e7140d2 to 728d0e4 Compare August 11, 2025 19:51
@Pankraz76
Pankraz76 requested a review from adangel August 12, 2025 07:54
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] New Rule: VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 12, 2025
@adangel adangel changed the title Fix #5770: [java] New Rule: VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 15, 2025
adangel added 3 commits August 15, 2025 11:09
@adangel
Fixups from review
52f38cc
@adangel
[doc] Update release notes (pmd#5770, pmd#5847)
2cce1fe
@adangel
Merge branch 'main' into pr-5847
a2eb2e4
adangel
adangel approved these changes Aug 15, 2025
View reviewed changes

@adangel adangel left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I've updated the PR myself (you seem to have not noticed the comments in the middle?).

If CI looks good, I'll merge it later today.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/resources/rulesets/java/quickstart.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/VariableCanBeInlined.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 7.17.0 milestone Aug 15, 2025
@adangel
adangel merged commit 2010efe into pmd:main Aug 15, 2025
@Pankraz76 Pankraz76 mentioned this pull request Sep 1, 2025
S1124: Modifiers should be declared in the correct order #6019
Closed
@adangel adangel changed the title Fix #5770: [java] New Rule: VariableCanBeInlined [java] Fix #5770: New Rule: VariableCanBeInlined Sep 8, 2025
@adangel adangel mentioned this pull request Sep 12, 2025
[java] UnnecessaryLocalBeforeReturn/VariableCanBeInlined: deprecate property statementOrderMatters #3124
Closed
@fudianchn fudianchn mentioned this pull request Sep 12, 2026
[java] Fix #3124: Deprecate statementOrderMatters property of VariableCanBeInlined #7065
Merged
3 of 4 tasks
UncleOwen added a commit that referenced this pull request Sep 13, 2026
@fudianchn @UncleOwen
[java] Deprecate statementOrderMatters property of VariableCanBeInlin…
6c8bbe8
…ed (refs #3124) (#7065)

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

The property silently migrated into the replacement rule when
UnnecessaryLocalBeforeReturn was deprecated (#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]>

* New rule name in changelog entry

* We really don't need a test for that.

Only make actually removing the property harder.

* Explicitely call out the deprecation/removal version.

---------

Signed-off-by: 付典 <[email protected]>
Co-authored-by: Sören Glimm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

7.17.0

Development

Successfully merging this pull request may close these issues.

[java] New Rule: VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Pankraz76 @oowekyala @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.