Repository navigation
[java] Fix #7063: CheckResultSet false positive with next() as ternary condition - #7066
Merged
Merged
Conversation
3 tasks done
TanbirRamim
force-pushed
the
fix-7063-checkresultset-ternary
branch
from
September 25, 2026 03:08
c3739a5 to
ed473dc
Compare
TanbirRamim
force-pushed
the
fix-7063-checkresultset-ternary
branch
from
October 4, 2026 19:20
ed473dc to
15e0f88
Compare
…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
force-pushed
the
fix-7063-checkresultset-ternary
branch
from
October 6, 2026 16:48
15e0f88 to
fe0dffd
Compare
Contributor
|
Compared to main: (comment created at 2026-10-06 17:21:54+00:00 for fe0dffd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe the PR
CheckResultSet accepted
if (rs.next())but reportedrs.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?
./mvnw clean verifypasses (checked automatically by github actions)