[java] Fix #6517: UselessPureMethodCall: fix false negative for primitive streams#6524
Merged
Conversation
Contributor
|
The PR description is a bit misleading -- this checks for all non-void methods on Like in the other PRs, please rebase this to avoid unrelated changes. |
…o known-pure methods - fix pmd#6517 Add primitive stream types (IntStream, LongStream, DoubleStream) to KNOWN_PURE_METHODS so that any discarded non-void method call on these types is reported, not just peek. Previously only java.util.stream.Stream was listed; the three primitive stream variants were missing, causing a false negative for peek and all other non-void methods on those types.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
Contributor
|
Compared to main: (comment created at 2026-05-07 08:58:21+00:00 for 0da431c) |
adangel
added a commit
that referenced
this pull request
May 7, 2026
adangel
added a commit
that referenced
this pull request
May 7, 2026
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.
Summary
Root cause
UselessPureMethodCall depends on JavaRuleUtil.isKnownPure, which uses a known-pure invocation matcher list.
That list contained java.util.stream.Stream#(*) but did not include primitive stream types, so peek(...) on IntStream / LongStream / DoubleStream was not classified as pure and therefore not reported when its result was ignored.
Fix
Add primitive stream types to KNOWN_PURE_METHODS:
Verification
Fixes #6517