Fix for false positives EI_EXPOSE_REP in case of unmodifiable collections#2141
Fix for false positives EI_EXPOSE_REP in case of unmodifiable collections#2141KengoTODA merged 4 commits intospotbugs:masterfrom
EI_EXPOSE_REP in case of unmodifiable collections#2141Conversation
…ctions The methods `of` and `copyOf` of `List`, `Map` and `Set` return an unmodifiable collection. Thus if final fields are initiablized using these methods then returning them is not dangerous.
KengoTODA
left a comment
There was a problem hiding this comment.
I just resolved a conflict in the CHANGELOG, so I treat this PR as approved by two SpotBugs teammates.
|
This causes a regression, see: #2174 |
|
Also since this change I get hundreds of lines of spam in the console (running on Java 8): Does this require Java 11? |
I saw this on Java 17 too. |
|
I will check this. Actually, I tested the PR on several open-source projects and instead of regressions it reduced the number of false positives by a lot. First, we need to reproduce it somehow on a small example. |
|
Invalid signature: Ljava/util/Collections$UnmodifiableRandomAccessList <- Here, I see that a semicolon is missing from the signature. I will try to create a test case that fails on this before fixing this issue. |
The methods
ofandcopyOfofList,MapandSetreturn an unmodifiable collection. Thus if final fields are initiablized using these methods then returning them is not dangerous.Make sure these boxes are checked before submitting your PR -- thank you!
CHANGELOG.mdif you have changed SpotBugs code