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
Fix for false positives EI_EXPOSE_REP
in case of unmodifiable collections
#2141
Conversation
…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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
of
andcopyOf
ofList
,Map
andSet
return 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.md
if you have changed SpotBugs code