Skip to content

Commit

Permalink
code optimization (apache#3167)
Browse files Browse the repository at this point in the history
code optimization
  • Loading branch information
CrazyHZM authored and khanimteyaz committed Jan 18, 2019
1 parent 8ce6970 commit d9df5e2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.dubbo.rpc;

import org.apache.dubbo.common.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -58,7 +60,7 @@ public String getAttachment(String key) {
@Override
public String getAttachment(String key, String defaultValue) {
String result = attachments.get(key);
if (result == null || result.length() == 0) {
if (StringUtils.isEmpty(result)) {
result = defaultValue;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;

import java.net.InetSocketAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -364,7 +365,7 @@ public String getLocalAddressString() {
*/
public String getLocalHostName() {
String host = localAddress == null ? null : localAddress.getHostName();
if (host == null || host.length() == 0) {
if (StringUtils.isEmpty(host)) {
return getLocalHost();
}
return host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
public static final int SERIALIZATION_EXCEPTION = 5;
public static final int NO_INVOKER_AVAILABLE_AFTER_FILTER = 6;
private static final long serialVersionUID = 7815426752583648734L;
private int code; // RpcException cannot be extended, use error code for exception type to keep compatibility
/**
* RpcException cannot be extended, use error code for exception type to keep compatibility
*/
private int code;

public RpcException() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;

import java.io.Serializable;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -198,7 +199,7 @@ public String getAttachment(String key, String defaultValue) {
return defaultValue;
}
String value = attachments.get(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface GenericService {
* @param parameterTypes Parameter types
* @param args Arguments
* @return invocation return value
* @throws Throwable potential exception thrown from the invocation
* @throws GenericException potential exception thrown from the invocation
*/
Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;

Expand Down

0 comments on commit d9df5e2

Please sign in to comment.