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

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


The following commit(s) were added to refs/heads/3.0 by this push:
     new 29b761c3c7 fix for issue 10303 (#10306)
29b761c3c7 is described below

commit 29b761c3c75b4325c0ae72dc1b427042510a1f63
Author: chenziqiang666 <[email protected]>
AuthorDate: Tue Jul 12 13:35:19 2022 +0800

    fix for issue 10303 (#10306)
    
    * issue#10303
    fix for java.lang.NullPointerException
    
    * issue#10303
    fix for java.lang.NullPointerException
---
 .../src/main/java/org/apache/dubbo/common/URL.java |  4 +-
 .../dubbo/registry/client/InstanceAddressURL.java  | 46 ++++++++++++++++++----
 .../client/ServiceDiscoveryRegistryDirectory.java  | 11 ++++--
 3 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 2e1eb3a17a..29d9df99a8 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -135,7 +135,7 @@ class URL implements Serializable {
 
     protected URL() {
         this.urlAddress = null;
-        this.urlParam = null;
+        this.urlParam = URLParam.parse(new HashMap<>());
         this.attributes = null;
     }
 
@@ -145,7 +145,7 @@ class URL implements Serializable {
 
     public URL(URLAddress urlAddress, URLParam urlParam, Map<String, Object> 
attributes) {
         this.urlAddress = urlAddress;
-        this.urlParam = urlParam;
+        this.urlParam = null == urlParam ? URLParam.parse(new HashMap<>()) : 
urlParam;
         this.attributes = (attributes != null ? attributes.isEmpty() ? null : 
attributes : null);
     }
 
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
index 757f33345e..8e8b2f9424 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/InstanceAddressURL.java
@@ -55,7 +55,7 @@ public class InstanceAddressURL extends URL {
     private volatile transient Set<String> providerFirstParams;
     // one instance address url serves only one protocol.
     private final transient String protocol;
-    
+
     protected InstanceAddressURL() {
         this(null, null, null);
     }
@@ -242,6 +242,10 @@ public class InstanceAddressURL extends URL {
         }
 
         MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        if (null == serviceInfo) {
+            return getParameter(key);
+        }
+
         String value = serviceInfo.getMethodParameter(method, key, null);
         if (StringUtils.isNotEmpty(value)) {
             return value;
@@ -307,6 +311,10 @@ public class InstanceAddressURL extends URL {
             return false;
         }
 
+        if (null == serviceInfo) {
+            return false;
+        }
+
         return serviceInfo.hasMethodParameter(method, key);
     }
 
@@ -344,6 +352,10 @@ public class InstanceAddressURL extends URL {
         }
 
         MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        if (null == serviceInfo) {
+            return false;
+        }
+
         return serviceInfo.hasMethodParameter(method);
     }
 
@@ -427,7 +439,11 @@ public class InstanceAddressURL extends URL {
             return this;
         }
 
-       getServiceInfo(protocolServiceKey).addParameter(key, value);
+        MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        if (null != serviceInfo) {
+            serviceInfo.addParameter(key, value);
+        }
+
         return this;
     }
 
@@ -436,12 +452,20 @@ public class InstanceAddressURL extends URL {
             return this;
         }
 
-        getServiceInfo(protocolServiceKey).addParameterIfAbsent(key, value);
+        MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        if (null != serviceInfo) {
+            serviceInfo.addParameterIfAbsent(key, value);
+        }
+
         return this;
     }
 
     public URL addConsumerParams(String protocolServiceKey, Map<String, 
String> params) {
-        getServiceInfo(protocolServiceKey).addConsumerParams(params);
+        MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        if (null != serviceInfo) {
+            serviceInfo.addConsumerParams(params);
+        }
+
         return this;
     }
 
@@ -456,7 +480,12 @@ public class InstanceAddressURL extends URL {
         String suffix = "." + key;
         String protocolServiceKey = getProtocolServiceKey();
         if (StringUtils.isNotEmpty(protocolServiceKey)) {
-            for (String fullKey : 
getServiceInfo(protocolServiceKey).getAllParams().keySet()) {
+            MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+            if (null == serviceInfo) {
+                return null;
+            }
+
+            for (String fullKey : serviceInfo.getAllParams().keySet()) {
                 if (fullKey.endsWith(suffix)) {
                     return getParameter(fullKey);
                 }
@@ -477,7 +506,9 @@ public class InstanceAddressURL extends URL {
 
     @Override
     protected Map<String, Number> getServiceNumbers(String protocolServiceKey) 
{
-        return getServiceInfo(protocolServiceKey).getNumbers();
+        MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+
+        return null == serviceInfo ? new ConcurrentHashMap<>() : 
serviceInfo.getNumbers();
     }
 
     @Override
@@ -494,7 +525,8 @@ public class InstanceAddressURL extends URL {
 
     @Override
     protected Map<String, Map<String, Number>> getServiceMethodNumbers(String 
protocolServiceKey) {
-        return getServiceInfo(protocolServiceKey).getMethodNumbers();
+        MetadataInfo.ServiceInfo serviceInfo = 
getServiceInfo(protocolServiceKey);
+        return null == serviceInfo ? new ConcurrentHashMap<>() : 
serviceInfo.getMethodNumbers();
     }
 
     @Override
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
index 35995f3c45..bfe1b8b383 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
@@ -24,6 +24,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.Assert;
 import org.apache.dubbo.common.utils.CollectionUtils;
 import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.metadata.MetadataInfo;
 import org.apache.dubbo.registry.AddressListener;
 import org.apache.dubbo.registry.Constants;
 import org.apache.dubbo.registry.ProviderFirstParams;
@@ -324,7 +325,7 @@ public class ServiceDiscoveryRegistryDirectory<T> extends 
DynamicDirectory<T> {
         }
 
         if (oldURL instanceof OverrideInstanceAddressURL || newURL instanceof 
OverrideInstanceAddressURL) {
-            if(!(oldURL instanceof OverrideInstanceAddressURL && newURL 
instanceof OverrideInstanceAddressURL)) {
+            if (!(oldURL instanceof OverrideInstanceAddressURL && newURL 
instanceof OverrideInstanceAddressURL)) {
                 // sub-class changed
                 return true;
             } else {
@@ -334,8 +335,12 @@ public class ServiceDiscoveryRegistryDirectory<T> extends 
DynamicDirectory<T> {
             }
         }
 
-        return 
!oldURL.getMetadataInfo().getValidServiceInfo(getConsumerUrl().getProtocolServiceKey())
-            
.equals(newURL.getMetadataInfo().getValidServiceInfo(getConsumerUrl().getProtocolServiceKey()));
+        MetadataInfo.ServiceInfo oldServiceInfo = 
oldURL.getMetadataInfo().getValidServiceInfo(getConsumerUrl().getProtocolServiceKey());
+        if (null == oldServiceInfo) {
+            return false;
+        }
+
+        return 
!oldServiceInfo.equals(newURL.getMetadataInfo().getValidServiceInfo(getConsumerUrl().getProtocolServiceKey()));
     }
 
     private List<Invoker<T>> toMergeInvokerList(List<Invoker<T>> invokers) {

Reply via email to