Skip to content

Commit

Permalink
Fix URL issue (#13807)
Browse files Browse the repository at this point in the history
  • Loading branch information
namelessssssssssss authored Mar 1, 2024
1 parent 8fb2293 commit 860ad02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -525,7 +525,7 @@ public List<URL> getBackupUrls() {
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));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public URL addParametersIfAbsent(Map<String, String> parameters) {
}

public URL addParameters(String... pairs) {
if (pairs == null || pairs.length == 0) {
if (ArrayUtils.isEmpty(pairs)) {
return this;
}
if (pairs.length % 2 != 0) {
Expand Down Expand Up @@ -1589,9 +1589,9 @@ public Map<String, Object> getAttributes() {
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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -376,7 +377,7 @@ public URLBuilder addParametersIfAbsent(Map<String, String> parameters) {

@Override
public URLBuilder addParameters(String... pairs) {
if (pairs == null || pairs.length == 0) {
if (ArrayUtils.isEmpty(pairs)) {
return this;
}
if (pairs.length % 2 != 0) {
Expand Down Expand Up @@ -416,7 +417,7 @@ public URLBuilder removeParameters(Collection<String> keys) {

@Override
public URLBuilder removeParameters(String... keys) {
if (keys == null || keys.length == 0) {
if (ArrayUtils.isEmpty(keys)) {
return this;
}
for (String key : keys) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ protected <T extends URL> T newURL(URLAddress urlAddress, URLParam urlParam) {
}

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ public Map<String, Object> getAttributes() {
}

@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
Expand Down

0 comments on commit 860ad02

Please sign in to comment.