Rule S6204 intent is to use unmutable lists instead of mutable lists whenever possible. Specifically, the rule correctly suggests replacing stream.collect(Collectors.toList()); with stream.toList(); when there is no modification detected on the returned list, and thus, it is incorrect to define it as a mutable list.
To this end the rule recognizes several methods on List that constitute a modification and allows like e.g. add, set and others
Beginning with Java 21 List implements SequencedCollection and 4 additional methods modify the list and the rule must not suggest the use of Stream::toList().
i.e. List::addFirst, List::addLast, List::removeFirst, List::removeLast
Suggested implementation, see PR:
___________________
Discussion:
This is similar to the already solved case for removeIf:
Several other open issues discuss this rule java:S6204 but not specifically the use of these methods:
Can you give your context for this false-negative? I.e. are you on SonarQube Cloud? SonarQube for IDE (flavor and version)? SonarQube self-managed (flavor and version)?