Modifying the backing source during stream operations may cause unintended results.


The problem

From the javadoc for Non-interference:

Accordingly, behavioral parameters in stream pipelines whose source might not be concurrent should never modify the stream’s data source. A behavioral parameter is said to interfere with a non-concurrent data source if it modifies, or causes to be modified, the stream’s data source. The need for non-interference applies to all pipelines, not just parallel ones. Unless the stream source is concurrent, modifying a stream’s data source during execution hg of a stream pipeline can cause exceptions, incorrect answers, or nonconformant behavior.

That is, prefer this:
  .filter(x -> x < 5)
  .collect(Collectors.toList()) // Terminate stream before source modification.

to this:
  .filter(x -> x < 5)


Suppress false positives by adding the suppression annotation @SuppressWarnings("ModifySourceCollectionInStream") to the enclosing element.