Fix bug: Put a value into Collections.emptyMap(). - #31379
Merged
chenrujun merged 12 commits intoOct 12, 2022
Merged
Conversation
chenrujun
requested review from
Netyyyy,
backwind1233,
fangjian0423,
hui1110,
moarychan,
saragluna,
stliu and
yiliuTo
as code owners
October 11, 2022 08:57
Collaborator
|
API change check API changes are not detected in this pull request. |
chenrujun
force-pushed
the
issue_31190_put-a_value_into_Collections.emptyMap
branch
from
October 11, 2022 09:25
d5e54ae to
a3a8499
Compare
saragluna
requested changes
Oct 11, 2022
saragluna
reviewed
Oct 12, 2022
…2AuthorizedClientMap.
…PPER.readValue()". Because "deserialize" should just do the "deserialize" work. After wrapped by "Collections.unmodifiableMap()", the returned value's class is changed.
…erializeOAuth2AuthorizedClientMap(Collections.unmodifiableMap(authorizedClients)))".
…orizedClientMap" because: 1. "Collections.unmodifiableMap()" needs extra cost. 2. "serializeOAuth2AuthorizedClientMap"'s java doc already said that it will not modify the parameter.
chenrujun
force-pushed
the
issue_31190_put-a_value_into_Collections.emptyMap
branch
from
October 12, 2022 06:49
66ae153 to
4f75d30
Compare
saragluna
approved these changes
Oct 12, 2022
chenrujun
deleted the
issue_31190_put-a_value_into_Collections.emptyMap
branch
October 12, 2022 09:23
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.
Fix #31190
Root cause analysis
How to fix
Immutable as default. When get an object from another method, assume the object is immutable. If modification is necessary, create a new object then modify the new object. Doing like this will make code more robust.Discard this, because Immutable as default has extra costs. Use java doc to specify whether the object is mutable or not.Learn (How to avoid similar problem in the future)
Follow Immutable as default principal.Discard this, because Immutable as default has extra costs. Use java doc to specify whether the object is mutable or not.Extra information
RestTemplateBuilderfollowed Immutable as default principal: In each build step, it creates a newRestTemplateBuilderinstead of usingsetter. Here is screenshot: