Prohibit Map.of and provide alternative methods#4086
Merged
Conversation
dondonz
commented
Aug 16, 2025
| * instances that preserve insertion order, which is important for consistent serialization. | ||
| */ | ||
| @Internal | ||
| public final class LinkedHashMapFactory { |
Member
Author
There was a problem hiding this comment.
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
bbakerman
approved these changes
Aug 16, 2025
Contributor
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. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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