java:S6204 Collections.reverse(List) is not considered a modification

  • SonarLint for IntelliJ
  • IntelliJ IDEA 2023.1.2 (Ultimate Edition), Build #IU-231.9011.34, built on May 16, 2023
  • OpenJDK 17.0.6+10

When collection a Stream with Collectors.toList(), SonarLint java:S6204 issue suggests to use the Stream.toList() instead when the collected list is not going to be modified. Collections.reverse(List) seems not to be detected as a function implying mutation, even if annotated with @Contract(mutates = "param1").

import java.util.Collections;
import java.util.List;

class JavaS6204ListModification {
    void undetectedMutatedList() {
        List<Integer> toBeModifiedList = Stream.of(1, 2, 3)

Hi @Jueverhard,

Thank you for reporting.
Here is the ticket to track fixing the issue.

All the best,


1 Like