This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c75300  fixes #9086 to solve race condition issue. (#9588)
6c75300 is described below

commit 6c75300637b5181dec4585250f8046519cfba429
Author: zrlw <[email protected]>
AuthorDate: Fri Jan 21 16:25:33 2022 +0800

    fixes #9086 to solve race condition issue. (#9588)
    
    Fixes #9086 in master branch
---
 .../src/main/java/org/apache/dubbo/metadata/MetadataInfo.java    | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
index 4649620..a58055e 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
@@ -325,9 +325,10 @@ public class MetadataInfo implements Serializable {
         }
 
         public String getMethodParameter(String method, String key, String 
defaultValue) {
+            // set consumerMethodParams firstly to avoid NPE at race condition.
             if (methodParams == null) {
-                methodParams = URL.toMethodParameters(params);
                 consumerMethodParams = URL.toMethodParameters(consumerParams);
+                methodParams = URL.toMethodParameters(params);
             }
 
             String value = getMethodParameter(method, key, 
consumerMethodParams);
@@ -359,12 +360,14 @@ public class MetadataInfo implements Serializable {
         }
 
         public boolean hasMethodParameter(String method) {
+            // set consumerMethodParams firstly to NPE at race condition.
             if (methodParams == null) {
-                methodParams = URL.toMethodParameters(params);
                 consumerMethodParams = URL.toMethodParameters(consumerParams);
+                methodParams = URL.toMethodParameters(params);
             }
 
-            return consumerMethodParams.containsKey(method) || 
methodParams.containsKey(method);
+            return (CollectionUtils.isNotEmptyMap(consumerMethodParams) && 
consumerMethodParams.containsKey(method))
+                    || (CollectionUtils.isNotEmptyMap(methodParams) && 
methodParams.containsKey(method));
         }
 
         public String toDescString() {

Reply via email to