From 860ad02e1ed2cbe5842a611adfc7f1138c4862e0 Mon Sep 17 00:00:00 2001 From: namelessssssssssss <100946116+namelessssssssssss@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:20:07 +0800 Subject: [PATCH] Fix URL issue (#13807) --- .../main/java/org/apache/dubbo/common/URL.java | 16 ++++++++-------- .../java/org/apache/dubbo/common/URLBuilder.java | 7 ++++--- .../common/url/component/ServiceConfigURL.java | 4 ++-- .../com/alibaba/dubbo/common/DelegateURL.java | 4 ++-- 4 files changed, 16 insertions(+), 15 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 28c841996c9..0c7bb1e3e86 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 @@ -339,7 +339,7 @@ public static String decode(String value) { } static String appendDefaultPort(String address, int defaultPort) { - if (address != null && address.length() > 0 && defaultPort > 0) { + if (StringUtils.isNotEmpty(address) && defaultPort > 0) { int i = address.indexOf(':'); if (i < 0) { return address + ":" + defaultPort; @@ -525,7 +525,7 @@ public List getBackupUrls() { List urls = new ArrayList<>(); urls.add(this); String[] backups = getParameter(RemotingConstants.BACKUP_KEY, new String[0]); - if (backups != null && backups.length > 0) { + if (ArrayUtils.isNotEmpty(backups)) { for (String backup : backups) { urls.add(this.setAddress(backup)); } @@ -805,7 +805,7 @@ public boolean getParameter(String key, boolean defaultValue) { public boolean hasParameter(String key) { String value = getParameter(key); - return value != null && value.length() > 0; + return StringUtils.isNotEmpty(value); } public String getMethodParameterAndDecoded(String method, String key) { @@ -1061,7 +1061,7 @@ public URL addParametersIfAbsent(Map parameters) { } public URL addParameters(String... pairs) { - if (pairs == null || pairs.length == 0) { + if (ArrayUtils.isEmpty(pairs)) { return this; } if (pairs.length % 2 != 0) { @@ -1589,9 +1589,9 @@ public Map getAttributes() { return attributes == null ? Collections.emptyMap() : attributes; } - public URL addAttributes(Map attributes) { - if (attributes != null) { - attributes.putAll(attributes); + public URL addAttributes(Map attributeMap) { + if (attributeMap != null) { + attributes.putAll(attributeMap); } return this; } @@ -1718,7 +1718,7 @@ public boolean getServiceParameter(String service, String key, boolean defaultVa public boolean hasServiceParameter(String service, String key) { String value = getServiceParameter(service, key); - return value != null && value.length() > 0; + return StringUtils.isNotEmpty(value); } public float getPositiveServiceParameter(String service, String key, float defaultValue) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java index e5c18bdaafd..ad2ec5cdf28 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common; import org.apache.dubbo.common.url.component.ServiceConfigURL; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.model.ScopeModel; @@ -376,7 +377,7 @@ public URLBuilder addParametersIfAbsent(Map parameters) { @Override public URLBuilder addParameters(String... pairs) { - if (pairs == null || pairs.length == 0) { + if (ArrayUtils.isEmpty(pairs)) { return this; } if (pairs.length % 2 != 0) { @@ -416,7 +417,7 @@ public URLBuilder removeParameters(Collection keys) { @Override public URLBuilder removeParameters(String... keys) { - if (keys == null || keys.length == 0) { + if (ArrayUtils.isEmpty(keys)) { return this; } for (String key : keys) { @@ -458,7 +459,7 @@ public boolean hasMethodParameter(String method, String key) { return false; } String value = getMethodParameter(method, key); - return value != null && value.length() > 0; + return StringUtils.isNotEmpty(value); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceConfigURL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceConfigURL.java index b16b5d03250..a353bdab3ed 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceConfigURL.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/url/component/ServiceConfigURL.java @@ -113,12 +113,12 @@ protected T newURL(URLAddress urlAddress, URLParam urlParam) { } @Override - public URL addAttributes(Map attributes) { + public URL addAttributes(Map attributeMap) { Map newAttributes = new HashMap<>(); if (this.attributes != null) { newAttributes.putAll(this.attributes); } - newAttributes.putAll(attributes); + newAttributes.putAll(attributeMap); return new ServiceConfigURL(getUrlAddress(), getUrlParam(), newAttributes); } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/DelegateURL.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/DelegateURL.java index 918b7d8a92f..7757fc1ac4c 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/DelegateURL.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/DelegateURL.java @@ -854,8 +854,8 @@ public Map getAttributes() { } @Override - public org.apache.dubbo.common.URL addAttributes(Map attributes) { - return apacheUrl.addAttributes(attributes); + public org.apache.dubbo.common.URL addAttributes(Map attributeMap) { + return apacheUrl.addAttributes(attributeMap); } @Override