-
Notifications
You must be signed in to change notification settings - Fork 26.6k
When PropertyValue "parameters" is [null] or [EMPTY], return to HashMap that can be modified #12354
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
AlbumenJ
left a comment
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.
BTW, pls replace the PR subject as a considerable one and comment in English.
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.*; |
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.
Please do not use comma import
| public static Map<String, String> convertParameters(String[] parameters) { | ||
| if (ArrayUtils.isEmpty(parameters)) { | ||
| return Collections.emptyMap(); | ||
| return new HashMap<>(); |
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.
Null return in org.apache.dubbo.config.AbstractMethodConfig#getParameters is also need to be considered
…eters中put对象为空时,返回空的HashMap而不是EmptyMap以支持后续put
797ed4b to
8270187
Compare
|
|
||
| public Map<String, String> getParameters() { | ||
| return parameters; | ||
| this.parameters = Optional.ofNullable(parameters).orElseGet(HashMap::new); |
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.
Set the newly created map to this.
|
Kudos, SonarCloud Quality Gate passed! |








org.apache.dubbo.config.spring.util.DubboAnnotationUtils.convertParametersWhen the
puttarget is an empty String array, the emptyHashMapinstead ofjava.util.Collections.EmptyMapsupports subsequent scalableputoperations org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适 #12350What is the purpose of the change
So that
@DubbboService#parameter, even if empty, does not affect the extra put operation causing the program to throw an exception---->
Collections.emptyMap()is a special implementation of EmptyMap inside Collections that doesn't support change, so I don't think it makes any sense to set a Map of that type hereorg.apache.dubbo.config.AbstractMethodConfig#getParametersPrevents this function from returning null
---->
Verifying this change
......