openrewrite / openrewrite/rewrite-static-analysis
Change mutable public collections to immutable versions
Open
@coiouhkc is already working on this.
Since Jun 26, 2023.
recipe
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
public static final List<String> entries = Arrays.asList("A","B");
public static final List<String> entries = Collections.unmodifiableList(Arrays.asList("A","B"));
While List.of is also an option, it is important to note that List.of throws NPE for null access patterns (like contains) and that can be problematic.
var a = Collections.unmodifiableList(Arrays.asList("A","B"));
var b =Arrays.asList("A","B");
var c = List.of("A","B");
a.contains(null) // false
b.contains(null) // false
c.contains(null) // NPE
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.