Skip to content

Commit

Permalink
Merge pull request #1242, remove redundant null check.
Browse files Browse the repository at this point in the history
fixes #1231
  • Loading branch information
hqq2023623 authored and chickenlj committed Feb 24, 2018
1 parent b52879c commit 4bbc0dd
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,27 @@ public Result call() throws Exception {
.append(" ]")
.toString());
}
if (method != null) {
if (!Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
}
result = resultList.remove(0).getValue();
try {
if (method.getReturnType() != void.class
&& method.getReturnType().isAssignableFrom(result.getClass())) {
for (Result r : resultList) {
result = method.invoke(result, r.getValue());
}
} else {
for (Result r : resultList) {
method.invoke(result, r.getValue());
}
if (!Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
}
result = resultList.remove(0).getValue();
try {
if (method.getReturnType() != void.class
&& method.getReturnType().isAssignableFrom(result.getClass())) {
for (Result r : resultList) {
result = method.invoke(result, r.getValue());
}
} else {
for (Result r : resultList) {
method.invoke(result, r.getValue());
}
} catch (Exception e) {
throw new RpcException(
new StringBuilder(32)
.append("Can not merge result: ")
.append(e.getMessage()).toString(),
e);
}
} else {
} catch (Exception e) {
throw new RpcException(
new StringBuilder(32)
.append("Can not merge result because missing method [ ")
.append(merger)
.append(" ] in class [ ")
.append(returnType.getClass().getName())
.append(" ]")
.toString());
.append("Can not merge result: ")
.append(e.getMessage()).toString(),
e);
}
} else {
Merger resultMerger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public String setEnumNameProperty(String name) {

public String getEnumPropertyName() {
if (isEnumType()) {
Object result = getProperty(ENUM_PROPERTY_NAME).toString();
Object result = getProperty(ENUM_PROPERTY_NAME);
return result == null ? null : result.toString();
}
throw new IllegalStateException("The instance is not a enum wrapper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public boolean hasExtension(String name) {
if (name == null || name.length() == 0)
throw new IllegalArgumentException("Extension name == null");
try {
return getExtensionClass(name) != null;
this.getExtensionClass(name);
return true;
} catch (Throwable t) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static Map<String, String> split(List<String> list, String separator) {
return null;
}
Map<String, String> map = new HashMap<String, String>();
if (list == null || list.isEmpty()) {
if (list.isEmpty()) {
return map;
}
for (String item : list) {
Expand All @@ -113,7 +113,7 @@ public static List<String> join(Map<String, String> map, String separator) {
return null;
}
List<String> list = new ArrayList<String>();
if (map == null || map.size() == 0) {
if (map.size() == 0) {
return list;
}
for (Map.Entry<String, String> entry : map.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ && isPrimitive(method.getReturnType())) {
if (parameter == null || !parameter.attribute())
continue;
String key;
if (parameter != null && parameter.key() != null && parameter.key().length() > 0) {
if (parameter.key() != null && parameter.key().length() > 0) {
key = parameter.key();
} else {
int i = name.startsWith("get") ? 3 : 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ public List<URL> lookup(URL url) {
urls.addAll(values);
}
}
if (urls == null || urls.isEmpty()) {
if (urls.isEmpty()) {
List<URL> cacheUrls = getCacheUrls(url);
if (cacheUrls != null && !cacheUrls.isEmpty()) {
urls.addAll(cacheUrls);
}
}
if (urls == null || urls.isEmpty()) {
if (urls.isEmpty()) {
for (URL u : getRegistered()) {
if (UrlUtils.isMatch(url, u)) {
urls.add(u);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,14 @@ protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byt
String value = history.get(index);
if (value != null) {
byte[] b1 = value.getBytes();
if (message != null && message.length > 0) {
byte[] b2 = new byte[b1.length + message.length];
System.arraycopy(b1, 0, b2, 0, b1.length);
System.arraycopy(message, 0, b2, b1.length, message.length);
message = b2;
} else {
message = b1;
}
byte[] b2 = new byte[b1.length + message.length];
System.arraycopy(b1, 0, b2, 0, b1.length);
System.arraycopy(message, 0, b2, b1.length, message.length);
message = b2;
}
}
String result = toString(message, getCharset(channel));
if (result != null && result.trim().length() > 0) {
if (result.trim().length() > 0) {
if (history == null) {
history = new LinkedList<String>();
channel.setAttribute(HISTORY_LIST_KEY, history);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ public Object reply(ExchangeChannel channel, Object message) throws RemotingExce
}
}
if (!hasMethod) {
logger.warn(new IllegalStateException("The methodName " + inv.getMethodName()
logger.warn(new IllegalStateException("The methodName " + inv.getMethodName()
+ " not found in callback service interface ,invoke will be ignored."
+ " please update the api interface. url is:"
+ " please update the api interface. url is:"
+ invoker.getUrl()) + " ,invocation is :" + inv);
return null;
}
}
RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
return invoker.invoke(inv);
}
throw new RemotingException(channel, "Unsupported request: "
+ (message == null ? null : (message.getClass().getName() + ": " + message))
throw new RemotingException(channel, "Unsupported request: "
+ (message == null ? null : (message.getClass().getName() + ": " + message))
+ ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void fireInvokeCallback(final Invoker<?> invoker, final Invocation invoc
if (onInvokeMethod == null || onInvokeInst == null) {
throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onreturn callback config , but no such " + (onInvokeMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl());
}
if (onInvokeMethod != null && !onInvokeMethod.isAccessible()) {
if (!onInvokeMethod.isAccessible()) {
onInvokeMethod.setAccessible(true);
}

Expand All @@ -133,7 +133,7 @@ private void fireReturnCallback(final Invoker<?> invoker, final Invocation invoc
if (onReturnMethod == null || onReturnInst == null) {
throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onreturn callback config , but no such " + (onReturnMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl());
}
if (onReturnMethod != null && !onReturnMethod.isAccessible()) {
if (!onReturnMethod.isAccessible()) {
onReturnMethod.setAccessible(true);
}

Expand Down Expand Up @@ -173,7 +173,7 @@ private void fireThrowCallback(final Invoker<?> invoker, final Invocation invoca
if (onthrowMethod == null || onthrowInst == null) {
throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onthrow callback config , but no such " + (onthrowMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl());
}
if (onthrowMethod != null && !onthrowMethod.isAccessible()) {
if (!onthrowMethod.isAccessible()) {
onthrowMethod.setAccessible(true);
}
Class<?>[] rParaTypes = onthrowMethod.getParameterTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void prepareConnection(HttpURLConnection con,
HttpComponentsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new HttpComponentsHttpInvokerRequestExecutor();
httpInvokerRequestExecutor.setReadTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
httpProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
} else if (client != null && client.length() > 0) {
} else {
throw new IllegalStateException("Unsupported http protocol client " + client + ", only supported: simple, commons");
}
httpProxyFactoryBean.afterPropertiesSet();
Expand Down

0 comments on commit 4bbc0dd

Please sign in to comment.