-
Notifications
You must be signed in to change notification settings - Fork 727
SONARJAVA-4426 S5778 allow calling factory methods to create empty collections #5633
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
Merged
tomasz-tylenda-sonarsource
merged 7 commits into
master
from
tt/SONARJAVA-4426-empty-col-rt-ex
May 27, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
30861b0
S5778 allow calling factory methods to create empty collections
tomasz-tylenda-sonarsource 70a899a
Fix autoscan diff
tomasz-tylenda-sonarsource 0a70d65
Fix ruling diff
tomasz-tylenda-sonarsource 545a690
Add Collections.singleton*
tomasz-tylenda-sonarsource e528357
comment
tomasz-tylenda-sonarsource e930298
3 more autoscan FNs
tomasz-tylenda-sonarsource c03ac2f
S5961 +1 autoscan
tomasz-tylenda-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "ruleKey": "S5778", | ||
| "hasTruePositives": false, | ||
| "falseNegatives": 32, | ||
| "falseNegatives": 44, | ||
| "falsePositives": 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "ruleKey": "S5961", | ||
| "hasTruePositives": false, | ||
| "falseNegatives": 5, | ||
| "falseNegatives": 6, | ||
| "falsePositives": 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looks good, I've seen your comment under the jira ticket, but there are many otheres non-raising functions, here are a few commonly used that could make sense to add.
Collections.singleton*: Collections.singleton(o) / Collections.singletonList(o) / Collections.singletonMap(k, v)...*.of:Stream.of(t)/Optional.ofNullable(v)...Byte.valueOf(b),Boolean.valueOf(b),Integer.valueOf(i)I'm not requesting any change, just proposing very commonly used functions you can add if you think it makes sense
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 added
Collections.singleton*.Arrays.asListcan throw NPE. While the other examples can lead to FPs, I don't think we should be adding a large collection of cases unless we have some evidence that they happen in practice.I think we can validate this PR on Peachee and follow up if we see more cases worth excluding.
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.
Sounds good!