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 #6517: UselessPureMethodCall: fix false negative for primitive streams by leemeii · Pull Request #6524 · pmd/pmd

Conversation

@leemeii

@leemeii leemeii commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • fix false negative in UselessPureMethodCall for discarded peek(...) calls on IntStream, LongStream, and DoubleStream
  • add regression test covering Stream + three primitive stream variants

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:

  • java.util.stream.IntStream#(*)
  • java.util.stream.LongStream#(*)
  • java.util.stream.DoubleStream#(*)

Verification

  • ran mvn test -Dtest=UselessPureMethodCallTest in pmd-java
  • result: 23 tests, 0 failures

Fixes #6517

Sorry, something went wrong.

Uh oh!

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

All reactions
@zbynek

zbynek commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

The PR description is a bit misleading -- this checks for all non-void methods on IntStream / DoubleStream / LongStream, which is good, but not specific to peek.

Like in the other PRs, please rebase this to avoid unrelated changes.

All reactions

Sorry, something went wrong.

Uh oh!

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

@leemeii
[java] UselessPureMethodCall: add IntStream/LongStream/DoubleStream t…
9fe8c5e
…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.
@leemeii
leemeii force-pushed the 6517 branch from 1f53371 to 9fe8c5e Compare April 1, 2026 08:34
@codacy-production

codacy-production Bot commented Apr 1, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

All reactions

Sorry, something went wrong.

Uh oh!

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

@adangel adangel changed the title [java] UselessPureMethodCall: fix false negative for primitive stream peek (#6517) [java] Fix #6517: UselessPureMethodCall: fix false negative for primitive stream peek May 7, 2026
@adangel adangel changed the title [java] Fix #6517: UselessPureMethodCall: fix false negative for primitive stream peek [java] Fix #6517: UselessPureMethodCall: fix false negative for primitive stream May 7, 2026
@adangel adangel changed the title [java] Fix #6517: UselessPureMethodCall: fix false negative for primitive stream [java] Fix #6517: UselessPureMethodCall: fix false negative for primitive streams May 7, 2026
@adangel
Merge branch 'main' into 6517
0da431c
@adangel adangel added this to the 7.25.0 milestone May 7, 2026
@pmd-actions-helper

pmd-actions-helper Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 1 new violations, 0 new errors and 0 new configuration errors,
removes 0 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-05-07 08:58:21+00:00 for 0da431c)

All reactions

Sorry, something went wrong.

Uh oh!

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

adangel
adangel approved these changes May 7, 2026
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!

Sorry, something went wrong.

Uh oh!

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

All reactions
@adangel
adangel merged commit 0da431c into pmd:main May 7, 2026
11 checks passed

Uh oh!

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

adangel added a commit that referenced this pull request May 7, 2026
@adangel
[doc] Update release notes (#6517, #6524)
c2f7da7
adangel added a commit that referenced this pull request May 7, 2026
@adangel
[java] Fix #6517: UselessPureMethodCall: fix false negative for primi…
7ca791f
…tive streams (#6524)
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

None yet

Projects

None yet

Milestone

7.25.0

Development

Successfully merging this pull request may close these issues.

[java] UselessPureMethodCall: False negative for methods on IntStream/LongStream/DoubleStream

Uh oh!

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

3 participants

@leemeii @zbynek @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.