-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Prohibit Map.of and provide alternative methods #4086
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
Conversation
| * instances that preserve insertion order, which is important for consistent serialization. | ||
| */ | ||
| @Internal | ||
| public final class LinkedHashMapFactory { |
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.
This is verbose. Originally I was only going to have one method (the last one) with variable length parameters, but saw the original Map.java had all of these extra methods for performance.
I don't think the difference is massive for our purposes, but I thought I'd follow the original
Test Results 326 files - 649 326 suites - 649 3m 31s ⏱️ - 7m 22s Results for commit 11d1357. ± Comparison against base commit 9c92725. This pull request removes 558 and adds 189 tests. Note that renamed tests count towards both.This pull request skips 1 test. |
Fixes #3989
Turns out Map.of doesn't guarantee consistent order when serialized, which is easy to forget. This PR adds an ArchUnit rule to ban it.
Additionally I created LinkedHashMap equivalents of Map.of to make things easier. It is verbose but intended to be a copy of the original Map methods.
Sample error message for ArchUnit test