
* Revert "Modify rules S2259;S2583;S2589;S3518;S3655;S3959 Remove replacement rules and update description for deprecated SE rules (#4207)" This reverts commit d4d145e532aa487392b1e273e205854f68eb1328. * Revert "SONARJAVA-5102 Deprecate Java SE rules implemented by DBD (#4177)" This reverts commit 952c1cab7b996d1a3e5060bc91745df6543d7eaf.
39 lines
1006 B
Plaintext
39 lines
1006 B
Plaintext
== Why is this an issue?
|
|
|
|
Stream operations are divided into intermediate and terminal operations, and are combined to form stream pipelines. After the terminal operation is performed, the stream pipeline is considered consumed, and cannot be used again. Such a reuse will yield unexpected results.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
Stream<Widget> pipeline = widgets.stream().filter(b -> b.getColor() == RED);
|
|
int sum1 = pipeline.sum();
|
|
int sum2 = pipeline.mapToInt(b -> b.getWeight()).sum(); // Noncompliant
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps[Stream Operations]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Refactor this code so that this consumed stream pipeline is not reused.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: Operation invoked on consumed stream
|
|
|
|
Secondary: The previous terminal operation on that stream
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|