This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 860ad02e1e Fix URL issue (#13807)
860ad02e1e is described below
commit 860ad02e1ed2cbe5842a611adfc7f1138c4862e0
Author: namelessssssssssss
<[email protected]>
AuthorDate: Fri Mar 1 14:20:07 2024 +0800
Fix URL issue (#13807)
---
.../src/main/java/org/apache/dubbo/common/URL.java | 16 ++++++++--------
.../main/java/org/apache/dubbo/common/URLBuilder.java | 7 ++++---
.../dubbo/common/url/component/ServiceConfigURL.java | 4 ++--
.../main/java/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 28c841996c..0c7bb1e3e8 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 /*final**/ class URL implements Serializable {
}
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 /*final**/ class URL implements Serializable {
List<URL> 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 /*final**/ class URL implements Serializable {
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 /*final**/ class URL implements Serializable {
}
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 /*final**/ class URL implements Serializable {
return attributes == null ? Collections.emptyMap() : attributes;
}
- public URL addAttributes(Map<String, Object> attributes) {
- if (attributes != null) {
- attributes.putAll(attributes);
+ public URL addAttributes(Map<String, Object> attributeMap) {
+ if (attributeMap != null) {
+ attributes.putAll(attributeMap);
}
return this;
}
@@ -1718,7 +1718,7 @@ public /*final**/ class URL implements Serializable {
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 e5c18bdaaf..ad2ec5cdf2 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 final class URLBuilder extends ServiceConfigURL {
@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 final class URLBuilder extends ServiceConfigURL {
@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 final class URLBuilder extends ServiceConfigURL {
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 b16b5d0325..a353bdab3e 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 @@ public class ServiceConfigURL extends URL {
}
@Override
- public URL addAttributes(Map<String, Object> attributes) {
+ public URL addAttributes(Map<String, Object> attributeMap) {
Map<String, Object> 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 918b7d8a92..7757fc1ac4 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 class DelegateURL extends
com.alibaba.dubbo.common.URL {
}
@Override
- public org.apache.dubbo.common.URL addAttributes(Map<String, Object>
attributes) {
- return apacheUrl.addAttributes(attributes);
+ public org.apache.dubbo.common.URL addAttributes(Map<String, Object>
attributeMap) {
+ return apacheUrl.addAttributes(attributeMap);
}
@Override