Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codemod sonar:java/replace-stream-collectors-to-list-s6204 may break code #349

Open
andrecsilva opened this issue Apr 15, 2024 · 2 comments

Comments

@andrecsilva
Copy link
Contributor

Despite the recommendation from the associated sonar rule to replace:

List<Integer> numbers = someStream.collect(Collectors.toList());
List<Integer> numbers = someStream.toList();

These are not the same. The second one results in a guaranteed unmodifiable list while the first one doesn't guarantee anything but the current implementation return a modifiable list.

In fact, this kind of change breaks our own code. See PR #348.

@nahsra
Copy link
Contributor

nahsra commented Apr 18, 2024

Do you have a suggestion for what to do about it?

Trying to detect if the List is mutated seems like folly, since even in our own code's example, the mutation happens after the List is returned from the function its in.

@andrecsilva
Copy link
Contributor Author

andrecsilva commented Apr 18, 2024

Do you have a suggestion for what to do about it?

Trying to detect if the List is mutated seems like folly, since even in our own code's example, the mutation happens after the List is returned from the function its in.

I don't think there is any other simple solution other than that.
Other than outright disable this, we could mark this as merge after review and warn them in the docs about possible breakage like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants