Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3959

Consumed Stream pipelines should not be reused

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Refactor this code so that this consumed stream pipeline is not reused.
    • Highlighting:
      Hide

      Primary: Operation invoked on consumed stream
      Secondary: The previous terminal operation on that stream

      Show
      Primary: Operation invoked on consumed stream Secondary: The previous terminal operation on that stream
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Java
    • Irrelevant for Languages:
      ABAP, C#, C, C++, Cobol, CSS, Flex, HTML, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      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

      Stream<Widget> pipeline = widgets.stream().filter(b -> b.getColor() == RED);
      int sum1 = pipeline.sum();
      int sum2 = pipeline.mapToInt(b -> b.getWeight()).sum(); // Noncompliant
      

      See

      Stream Operations

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeanchristophe.collet Jean-Christophe Collet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: