Skip to content

[java] Fix #7063: CheckResultSet false positive with next() as ternary condition - #7066

Merged
UncleOwen merged 1 commit into
pmd:mainfrom
TanbirRamim:fix-7063-checkresultset-ternary
Oct 8, 2026
Merged

UncleOwen merged 1 commit into
pmd:mainfrom
TanbirRamim:fix-7063-checkresultset-ternary

Conversation

@TanbirRamim

Copy link
Copy Markdown
Contributor

Describe the PR

CheckResultSet accepted if (rs.next()) but reported rs.next() ? rs.getInt(1) : 0, even though both check the return value. The rule now treats a navigation call inside the condition of a conditional expression as checked, while calls in the branches are still reported. This only fixes the ternary case and does not attempt the wider rework discussed in #5031 and #5209. I added rule test cases for the lambda from the issue, assignments, negation and && in the condition, plus one that should still be reported, and ran the full pmd-java test suite and checkstyle.

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)

Copilot AI lite review requested due to automatic review settings September 12, 2026 23:58

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@TanbirRamim
TanbirRamim force-pushed the fix-7063-checkresultset-ternary branch from c3739a5 to ed473dc Compare September 25, 2026 03:08
@TanbirRamim
TanbirRamim force-pushed the fix-7063-checkresultset-ternary branch from ed473dc to 15e0f88 Compare October 4, 2026 19:20
…nary condition

CheckResultSet accepted rs.next() as the condition of an if or while
statement, but reported it when used as the condition of a conditional
expression like rs.next() ? rs.getInt(1) : 0. Calls inside the condition
of a ternary are now treated as checked, the same as for if statements.
@TanbirRamim
TanbirRamim force-pushed the fix-7063-checkresultset-ternary branch from 15e0f88 to fe0dffd Compare October 6, 2026 16:48
@pmd-actions-helper

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-10-06 17:21:54+00:00 for fe0dffd)

@UncleOwen UncleOwen added this to the 7.29.0 milestone Oct 8, 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 cfee948 into pmd:main Oct 8, 2026
13 checks passed
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] CheckResultSet: False positive for rs.next() ? x : y

3 participants