java:S6204 List.removeIf(Predicate) is not considered a modification

  • SonarLint for Eclipse
  • Eclipse 2021-09 (4.21.0), build id: 20210910-1417
  • openjdk version “16.0.2” 2021-07-20, OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, sharing)

When collecting a Stream with Collectors.toList() in Java 16+, S6204 suggests to use the new method Stream.toList() to collect to an unmodifyable List, apart from cases where the List is modified afterwards. List.removeIf(Predicate) seems to be not considered a modification and gives a false-positive:

import java.util.List;

class S6204ListModification {

    void mutatedList() {
        List<String> list = Stream.of("").collect(Collectors.toList());
        list.removeIf(s -> true);

Hi @Madjosz,

Thank you for your report. Indeed removeIf is missing from the list. I’ve created a ticket.


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