Skip to content

[java] Fix #6625: New rule: UnusedReturnValue - #6916

Merged
UncleOwen merged 9 commits into
pmd:mainfrom
UncleOwen:issue-6625-new-rule-UnusedReturnValue
Aug 9, 2026
Merged

UncleOwen merged 9 commits into
pmd:mainfrom
UncleOwen:issue-6625-new-rule-UnusedReturnValue

Conversation

@UncleOwen

@UncleOwen UncleOwen commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Describe the PR

This rule uses multiple ways to find method calls where the return value is ignored but shouldn't be:

  • @CheckReturnValue annotation on method/class/package, unless overridden by a @CanIgnoreReturnValue annotation
  • methods that JavaRuleUtil.isKnownPure determines to be pure. The existing rule UselessPureMethodCallRule is deprecated
  • methods in InputStream, that return the number of bytes read. The existing rule CheckSkipResultRule is deprecated. CheckSkipResultRule only checked .skip(), but ignoring the return value of .read() has the same problem

I did not include CheckResultSet. Although the rule claims it is about the return value of .next() and siblings, it is really about making sure that .getFoo() is only called when the object is in the correct state.

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)
  • [n/a] Added (in-code) documentation (if needed)

@UncleOwen UncleOwen added a:new-rule Proposal to add a new built-in rule is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them labels Jul 29, 2026
@pmd-actions-helper

pmd-actions-helper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 878 new violations, 0 new errors and 0 new configuration errors,
removes 857 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-08-07 16:06:02+00:00 for c4ca084)

@UncleOwen
UncleOwen force-pushed the issue-6625-new-rule-UnusedReturnValue branch from 612b993 to 4db560b Compare August 1, 2026 20:51
@UncleOwen
UncleOwen requested a review from lukasgraef August 7, 2026 16:13

@lukasgraef lukasgraef 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.

Looks good!

I especially like the updated error messages compared to the previous deprecated rules.

@UncleOwen
UncleOwen merged commit 578f01f into pmd:main Aug 9, 2026
13 checks passed
@UncleOwen
UncleOwen deleted the issue-6625-new-rule-UnusedReturnValue branch August 9, 2026 10:39
@UncleOwen UncleOwen added this to the 7.27.0 milestone Aug 9, 2026
@adangel adangel mentioned this pull request Aug 13, 2026
4 tasks
@adangel adangel changed the title [java] Fix #6625: new rule UnusedReturnValue [java] Fix #6625: New rule UnusedReturnValue Aug 14, 2026
@adangel adangel changed the title [java] Fix #6625: New rule UnusedReturnValue [java] Fix #6625: New rule: UnusedReturnValue Aug 14, 2026
adangel added a commit that referenced this pull request Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule 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] New rule: UnusedReturnValue

2 participants