java:S6204 suggestion contradicts javadoc -- modifiable list

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.

1 Like

Hello @grossjohann and welcome to the Sonar Community.

Thank you for reporting this inaccuracy; [SONARJAVA-5056] - Jira will take care of updating the documentation.

Cheers,
Angelo