[S3958] Stream#toList (JDK 16) is not recognized as terminal operator

The new Stream#toList() method in JDK16 is not recognized as terminal operator by SonarLint and triggers this error:

Intermediate Stream methods should not be left unused

Bug

Major
java:S3958

Versions used:

  • InteliJ: IntelliJ IDEA 2021.1 (Ultimate Edition) Build #IU-211.6693.111
  • SonarLint plugin for InteliJ: 4.14.2.28348
  • JDK 16 (AdoptOpenJDK 16.0.0.j9)

Minimal code sample to reproduce:

  private List<String> test() {
    return Stream
        .of("test")
        .map(String::toUpperCase) //removing this line suppresses the error 
        .toList();
  }

Hey @MartinBG

This should be addressed when we bring full support of Java 16 to our products: you can track SONARJAVA-3746 for this specific case and MMF-2317 for the broader effort.

This all has a dependency on the release of a new version of the ECJ (SONARJAVA-3738) so probably early summertime.

2 Likes

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