# \[Java:S3958\] Falsely reports unused stream pipeline

**URL:** <https://community.sonarsource.com/t/java-s3958-falsely-reports-unused-stream-pipeline/32974>\
**Category:** SonarQube Cloud\
**Tags:** java, sonarqube-cloud\
**Created:** [October 15, 2020, 1:49pm UTC](https://community.sonarsource.com/t/java-s3958-falsely-reports-unused-stream-pipeline/32974 "2020-10-15T13:49:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grimsa](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/grimsa/32/11633_2.png) [@grimsa](https://community.sonarsource.com/u/grimsa)\
**Post date:** [October 15, 2020, 1:49pm UTC](https://community.sonarsource.com/t/java-s3958-falsely-reports-unused-stream-pipeline/32974/1 "2020-10-15T13:49:48Z")

</div>

Version used: SonarCloud  
Java compiler source and target versions: 14

Simplified method with which the issue should be reproduced:

```auto
    public Stream<Double> method() {
        Stream<Double> streamOfNumbers = Stream.of(1d, 2d, 3d);
        return Optional.of(new Random().nextDouble())
                .filter(randomNumber -> randomNumber < 0.99)
                .map(randomNumber -> streamOfNumbers.map(number -> number + randomNumber))
                .orElse(streamOfNumbers);
    }

```

In both cases we are returning the same stream, except in once case it gets an extra `.map` intermediate operation.

Actual method and FP:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/7/9/79810587358dd033787eccd8c37e0adff4211a03.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [November 4, 2020, 5:06pm UTC](https://community.sonarsource.com/t/java-s3958-falsely-reports-unused-stream-pipeline/32974/3 "2020-11-04T17:06:06Z")

</div>

Hey @grimsa,

Thanks a lot for the feedback and reproducer. I created the following ticket to handle it: [SONARJAVA-3604](https://jira.sonarsource.com/browse/SONARJAVA-3604)

Note that this rule is based on our internal symbolic execution engine, which shows some limitations when exploring stream and lambdas. I scheduled the ticket for our next Java Analyzer release, but I can not guarantee that we will manage to fix it by then.

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [November 11, 2020, 5:06pm UTC](https://community.sonarsource.com/t/java-s3958-falsely-reports-unused-stream-pipeline/32974/5 "2020-11-11T17:06:22Z")

</div>

Closed on November 11, 2020, 5:06pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
