The rule java:S6204 suggests .collect(Collectors.toList())
to create a modifiable list, but the javadoc for Collectors.toList
states that it does not make any guarantees about the returned list being modifiable.
Link to documentation: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html#toList()
It feels like an API design mistake. If I want a modifiable list, I have to use toCollection
and specify the concrete list I want, it seems.