You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/11/16 08:13:12 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10921: fix NPE bug of URL

AlbumenJ commented on code in PR #10921:
URL: https://github.com/apache/dubbo/pull/10921#discussion_r1023648421


##########
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java:
##########
@@ -499,8 +529,15 @@ public String getPath() {
     }
 
     public URL setPath(String path) {
-        URLAddress newURLAddress = urlAddress.setPath(path);
-        return returnURL(newURLAddress);
+        URL url;
+        if (urlAddress == null) {
+            url = new URL();
+            url.setPath(path);
+        } else {
+            URLAddress newURLAddress = urlAddress.setPath(path);
+            url = returnURL(newURLAddress);
+        }
+        return url;

Review Comment:
   ```suggestion
           if (urlAddress == null) {
               return new ServiceConfigURL(getProtocol(), getHost(), getPort(), path, getParameters());
           } else {
               URLAddress newURLAddress = urlAddress.setPath(path);
               return returnURL(newURLAddress);
           }
   ```



##########
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java:
##########
@@ -425,8 +433,15 @@ public String getHost() {
     }
 
     public URL setHost(String host) {
-        URLAddress newURLAddress = urlAddress.setHost(host);
-        return returnURL(newURLAddress);
+        URL url;
+        if (urlAddress == null) {
+            url = new URL();
+            url.setHost(host);
+        } else {
+            URLAddress newURLAddress = urlAddress.setHost(host);
+            url = returnURL(newURLAddress);
+        }
+        return url;

Review Comment:
   ```suggestion
   ```suggestion
           if (urlAddress == null) {
               return new ServiceConfigURL(getProtocol(), host, getPort(), getPath(), getParameters());
           } else {
               URLAddress newURLAddress = urlAddress.setHost(host);
               return returnURL(newURLAddress);
           }
   ```
   ```



##########
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java:
##########
@@ -458,12 +480,20 @@ public URL setAddress(String address) {
         } else {
             host = address;
         }
-        URLAddress newURLAddress = urlAddress.setAddress(host, port);
-        return returnURL(newURLAddress);
+        URL url;
+        if (urlAddress == null) {
+            url = new URL();
+            url.setHost(host);
+            url.setPort(port);
+        } else {
+            URLAddress newURLAddress = urlAddress.setAddress(host, port);
+            url = returnURL(newURLAddress);
+        }
+        return url;

Review Comment:
   ```suggestion
           if (urlAddress == null) {
               return new ServiceConfigURL(getProtocol(), host, port, getPath(), getParameters());
           } else {
               URLAddress newURLAddress = urlAddress.setAddress(host, port);
               return returnURL(newURLAddress);
           }
   ```



##########
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java:
##########
@@ -435,8 +450,15 @@ public int getPort() {
     }
 
     public URL setPort(int port) {
-        URLAddress newURLAddress = urlAddress.setPort(port);
-        return returnURL(newURLAddress);
+        URL url;
+        if (urlAddress == null) {
+            url = new URL();
+            url.setPort(port);
+        } else {
+            URLAddress newURLAddress = urlAddress.setPort(port);
+            url = returnURL(newURLAddress);
+        }
+        return url;

Review Comment:
   ```suggestion
           if (urlAddress == null) {
               return new ServiceConfigURL(getProtocol(), getHost(), port, getPath(), getParameters());
           } else {
               URLAddress newURLAddress = urlAddress.setPort(port);
               return returnURL(newURLAddress);
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org