Skip to content

Commit

Permalink
Code format (apache#2662)
Browse files Browse the repository at this point in the history
* NullPointerException

* code rule
  • Loading branch information
x-ultimate authored and CrazyHZM committed Dec 6, 2018
1 parent 9425ac9 commit abe1c9a
Show file tree
Hide file tree
Showing 64 changed files with 1,571 additions and 939 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.support.RpcUtils;
Expand Down Expand Up @@ -138,10 +138,12 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List
}

private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
if (invokers == null || invokers.isEmpty())
if (invokers == null || invokers.isEmpty()) {
return null;
if (invokers.size() == 1)
}
if (invokers.size() == 1) {
return invokers.get(0);
}
Invoker<T> invoker = loadbalance.select(invokers, getUrl(), invocation);

//If the `invoker` is in the `selected` or invoker is unavailable && availablecheck is true, reselect.
Expand Down
116 changes: 80 additions & 36 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ public static URL valueOf(String url) {
}
i = url.indexOf("://");
if (i >= 0) {
if (i == 0) throw new IllegalStateException("url missing protocol: \"" + url + "\"");
if (i == 0) {
throw new IllegalStateException("url missing protocol: \"" + url + "\"");
}
protocol = url.substring(0, i);
url = url.substring(i + 3);
} else {
// case: file:/path/to/file.txt
i = url.indexOf(":/");
if (i >= 0) {
if (i == 0) throw new IllegalStateException("url missing protocol: \"" + url + "\"");
if (i == 0) {
throw new IllegalStateException("url missing protocol: \"" + url + "\"");
}
protocol = url.substring(0, i);
url = url.substring(i + 1);
}
Expand Down Expand Up @@ -246,7 +250,9 @@ public static URL valueOf(String url) {
url = url.substring(0, i);
}
}
if (url.length() > 0) host = url;
if (url.length() > 0) {
host = url;
}
return new URL(protocol, username, password, host, port, path, parameters);
}

Expand Down Expand Up @@ -915,17 +921,23 @@ public URL addParameter(String key, double value) {
}

public URL addParameter(String key, Enum<?> value) {
if (value == null) return this;
if (value == null) {
return this;
}
return addParameter(key, String.valueOf(value));
}

public URL addParameter(String key, Number value) {
if (value == null) return this;
if (value == null) {
return this;
}
return addParameter(key, String.valueOf(value));
}

public URL addParameter(String key, CharSequence value) {
if (value == null || value.length() == 0) return this;
if (value == null || value.length() == 0) {
return this;
}
return addParameter(key, String.valueOf(value));
}

Expand Down Expand Up @@ -984,7 +996,9 @@ public URL addParameters(Map<String, String> parameters) {
}
}
// return immediately if there's no change
if (hasAndEqual) return this;
if (hasAndEqual) {
return this;
}

Map<String, String> map = new HashMap<String, String>(getParameters());
map.putAll(parameters);
Expand Down Expand Up @@ -1055,35 +1069,47 @@ public URL clearParameters() {
}

public String getRawParameter(String key) {
if ("protocol".equals(key))
if ("protocol".equals(key)) {
return protocol;
if ("username".equals(key))
}
if ("username".equals(key)) {
return username;
if ("password".equals(key))
}
if ("password".equals(key)) {
return password;
if ("host".equals(key))
}
if ("host".equals(key)) {
return host;
if ("port".equals(key))
}
if ("port".equals(key)) {
return String.valueOf(port);
if ("path".equals(key))
}
if ("path".equals(key)) {
return path;
}
return getParameter(key);
}

public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>(parameters);
if (protocol != null)
if (protocol != null) {
map.put("protocol", protocol);
if (username != null)
}
if (username != null) {
map.put("username", username);
if (password != null)
}
if (password != null) {
map.put("password", password);
if (host != null)
}
if (host != null) {
map.put("host", host);
if (port > 0)
}
if (port > 0) {
map.put("port", String.valueOf(port));
if (path != null)
}
if (path != null) {
map.put("path", path);
}
return map;
}

Expand Down Expand Up @@ -1218,7 +1244,9 @@ public InetSocketAddress toInetSocketAddress() {

public String getServiceKey() {
String inf = getServiceInterface();
if (inf == null) return null;
if (inf == null) {
return null;
}
StringBuilder buf = new StringBuilder();
String group = getParameter(Constants.GROUP_KEY);
if (group != null && group.length() > 0) {
Expand Down Expand Up @@ -1359,45 +1387,61 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
URL other = (URL) obj;
if (host == null) {
if (other.host != null)
if (other.host != null) {
return false;
} else if (!host.equals(other.host))
}
} else if (!host.equals(other.host)) {
return false;
}
if (parameters == null) {
if (other.parameters != null)
if (other.parameters != null) {
return false;
} else if (!parameters.equals(other.parameters))
}
} else if (!parameters.equals(other.parameters)) {
return false;
}
if (password == null) {
if (other.password != null)
if (other.password != null) {
return false;
} else if (!password.equals(other.password))
}
} else if (!password.equals(other.password)) {
return false;
}
if (path == null) {
if (other.path != null)
if (other.path != null) {
return false;
} else if (!path.equals(other.path))
}
} else if (!path.equals(other.path)) {
return false;
if (port != other.port)
}
if (port != other.port) {
return false;
}
if (protocol == null) {
if (other.protocol != null)
if (other.protocol != null) {
return false;
} else if (!protocol.equals(other.protocol))
}
} else if (!protocol.equals(other.protocol)) {
return false;
}
if (username == null) {
if (other.username != null)
if (other.username != null) {
return false;
} else if (!username.equals(other.username))
}
} else if (!username.equals(other.username)) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,16 @@ private static Object instantiateForDeserialize(JavaBeanDescriptor beanDescripto
}
result = Array.newInstance(componentType, beanDescriptor.propertySize());
cache.put(beanDescriptor, result);
} else try {
Class<?> cl = name2Class(loader, beanDescriptor.getClassName());
result = instantiate(cl);
cache.put(beanDescriptor, result);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
} else {
try {
Class<?> cl = name2Class(loader, beanDescriptor.getClassName());
result = instantiate(cl);
cache.put(beanDescriptor, result);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

return result;
Expand Down
Loading

0 comments on commit abe1c9a

Please sign in to comment.