Skip to content

Commit e095bd9

Browse files
CrazyHZMcarryxyh
authored andcommitted
code optimization (#3167)
code optimization
1 parent ddb518d commit e095bd9

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.dubbo.rpc;
1818

19+
import org.apache.dubbo.common.utils.StringUtils;
20+
1921
import java.util.HashMap;
2022
import java.util.Map;
2123

@@ -58,7 +60,7 @@ public String getAttachment(String key) {
5860
@Override
5961
public String getAttachment(String key, String defaultValue) {
6062
String result = attachments.get(key);
61-
if (result == null || result.length() == 0) {
63+
if (StringUtils.isEmpty(result)) {
6264
result = defaultValue;
6365
}
6466
return result;

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
2222
import org.apache.dubbo.common.utils.NetUtils;
23+
import org.apache.dubbo.common.utils.StringUtils;
2324

2425
import java.net.InetSocketAddress;
2526
import java.util.ArrayList;
@@ -364,7 +365,7 @@ public String getLocalAddressString() {
364365
*/
365366
public String getLocalHostName() {
366367
String host = localAddress == null ? null : localAddress.getHostName();
367-
if (host == null || host.length() == 0) {
368+
if (StringUtils.isEmpty(host)) {
368369
return getLocalHost();
369370
}
370371
return host;

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
public static final int SERIALIZATION_EXCEPTION = 5;
3535
public static final int NO_INVOKER_AVAILABLE_AFTER_FILTER = 6;
3636
private static final long serialVersionUID = 7815426752583648734L;
37-
private int code; // RpcException cannot be extended, use error code for exception type to keep compatibility
37+
/**
38+
* RpcException cannot be extended, use error code for exception type to keep compatibility
39+
*/
40+
private int code;
3841

3942
public RpcException() {
4043
super();

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.dubbo.common.Constants;
2020
import org.apache.dubbo.common.URL;
21+
import org.apache.dubbo.common.utils.StringUtils;
2122

2223
import java.io.Serializable;
2324
import java.lang.reflect.Method;
@@ -198,7 +199,7 @@ public String getAttachment(String key, String defaultValue) {
198199
return defaultValue;
199200
}
200201
String value = attachments.get(key);
201-
if (value == null || value.length() == 0) {
202+
if (StringUtils.isEmpty(value)) {
202203
return defaultValue;
203204
}
204205
return value;

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface GenericService {
3131
* @param parameterTypes Parameter types
3232
* @param args Arguments
3333
* @return invocation return value
34-
* @throws Throwable potential exception thrown from the invocation
34+
* @throws GenericException potential exception thrown from the invocation
3535
*/
3636
Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;
3737

0 commit comments

Comments
 (0)