From 458a4504dc9e98792da83566959191f67280107a Mon Sep 17 00:00:00 2001 From: huazhongming Date: Wed, 16 Jan 2019 15:11:12 +0800 Subject: [PATCH] call the util method (#3230) * Code optimization, call the util method * mofidy * modify * * import package --- .../configurator/parser/ConfigParser.java | 2 +- .../cluster/directory/StaticDirectory.java | 5 +- .../loadbalance/AbstractLoadBalance.java | 3 +- .../router/condition/ConditionRouter.java | 9 +- .../cluster/router/script/ScriptRouter.java | 5 +- .../rpc/cluster/router/tag/TagRouter.java | 2 +- .../support/wrapper/MockClusterInvoker.java | 3 +- .../org/apache/dubbo/common/Parameters.java | 34 +++---- .../java/org/apache/dubbo/common/URL.java | 94 ++++++++++--------- .../java/org/apache/dubbo/common/Version.java | 9 +- .../dubbo/common/bytecode/ClassGenerator.java | 8 +- .../common/compiler/support/ClassUtils.java | 4 +- .../common/extension/ExtensionLoader.java | 16 ++-- .../dubbo/common/utils/CollectionUtils.java | 14 ++- .../dubbo/common/utils/ConfigUtils.java | 4 +- .../apache/dubbo/common/utils/UrlUtils.java | 10 +- .../dubbo/common/utils/PojoUtilsTest.java | 4 +- .../java/com/alibaba/dubbo/common/URL.java | 3 +- .../apache/dubbo/config/AbstractConfig.java | 2 +- .../dubbo/config/AbstractInterfaceConfig.java | 19 ++-- .../dubbo/config/AbstractServiceConfig.java | 3 +- .../dubbo/config/ApplicationConfig.java | 3 +- .../org/apache/dubbo/config/ModuleConfig.java | 6 +- .../apache/dubbo/config/ReferenceConfig.java | 19 ++-- .../apache/dubbo/config/ServiceConfig.java | 41 ++++---- .../dubbo/config/spring/AnnotationBean.java | 8 +- .../dubbo/config/spring/ConfigCenterBean.java | 3 +- .../dubbo/config/spring/ReferenceBean.java | 7 +- .../dubbo/config/spring/ServiceBean.java | 21 +++-- .../ReferenceAnnotationBeanPostProcessor.java | 3 +- .../schema/DubboBeanDefinitionParser.java | 10 +- .../status/DataSourceStatusChecker.java | 3 +- .../spring/AbstractRegistryService.java | 6 +- .../config/spring/SimpleRegistryService.java | 3 +- .../java/org/apache/dubbo/container/Main.java | 3 +- .../dubbo/container/log4j/Log4jContainer.java | 3 +- .../container/logback/LogbackContainer.java | 2 +- .../container/spring/SpringContainer.java | 3 +- .../dubbo/cache/support/jcache/JCache.java | 3 +- .../util/JaketConfigurationUtils.java | 8 +- .../monitor/dubbo/DubboMonitorFactory.java | 5 +- .../apache/dubbo/qos/command/impl/Online.java | 3 +- .../dubbo/qos/command/GreetingCommand.java | 3 +- .../integration/RegistryDirectory.java | 7 +- .../integration/RegistryProtocol.java | 3 +- .../registry/support/AbstractRegistry.java | 3 +- .../registry/support/FailbackRegistry.java | 3 +- .../registry/multicast/MulticastRegistry.java | 7 +- .../dubbo/registry/redis/RedisRegistry.java | 15 +-- .../registry/zookeeper/ZookeeperRegistry.java | 5 +- .../support/header/HeaderExchangeServer.java | 3 +- .../remoting/telnet/codec/TelnetCodec.java | 7 +- .../telnet/support/TelnetHandlerAdapter.java | 2 +- .../support/command/HelpTelnetHandler.java | 3 +- .../support/command/StatusTelnetHandler.java | 5 +- .../remoting/transport/AbstractClient.java | 3 +- .../transport/ChannelHandlerDispatcher.java | 3 +- .../codec/DeprecatedTelnetCodec.java | 2 +- .../remoting/transport/netty/NettyServer.java | 3 +- .../netty4/logging/FormattingTuple.java | 4 +- .../netty4/logging/MessageFormatter.java | 3 +- .../java/org/apache/dubbo/rpc/RpcContext.java | 3 +- .../dubbo/rpc/filter/AccessLogFilter.java | 3 +- .../rpc/listener/ListenerExporterWrapper.java | 5 +- .../rpc/listener/ListenerInvokerWrapper.java | 5 +- .../dubbo/rpc/protocol/AbstractInvoker.java | 3 +- .../apache/dubbo/rpc/support/MockInvoker.java | 3 +- .../dubbo/rpc/support/ProtocolUtils.java | 3 +- .../apache/dubbo/rpc/support/RpcUtils.java | 5 +- .../protocol/dubbo/filter/TraceFilter.java | 3 +- .../dubbo/rpc/protocol/http/HttpProtocol.java | 3 +- .../rpc/protocol/injvm/InjvmProtocol.java | 3 +- 72 files changed, 306 insertions(+), 233 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java index bffa1d628a..76d6f2db3a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java @@ -130,7 +130,7 @@ public class ConfigParser { sb.append(item.getSide()); } Map parameters = item.getParameters(); - if (parameters == null || parameters.isEmpty()) { + if (CollectionUtils.isEmptyMap(parameters)) { throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " + "you want to change in the rule."); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index 160543867c..cccbd12e3f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.cluster.directory; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; @@ -48,8 +49,8 @@ public class StaticDirectory extends AbstractDirectory { } public StaticDirectory(URL url, List> invokers, RouterChain routerChain) { - super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain); - if (invokers == null || invokers.isEmpty()) { + super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain); + if (CollectionUtils.isEmpty(invokers)) { throw new IllegalArgumentException("invokers == null"); } this.invokers = invokers; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index feb9202d50..78151ed5af 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster.loadbalance; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.cluster.LoadBalance; @@ -44,7 +45,7 @@ public abstract class AbstractLoadBalance implements LoadBalance { @Override public Invoker select(List> invokers, URL url, Invocation invocation) { - if (invokers == null || invokers.isEmpty()) { + if (CollectionUtils.isEmpty(invokers)) { return null; } if (invokers.size() == 1) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java index 434ef8cb23..844b1b846f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; @@ -101,7 +102,7 @@ public class ConditionRouter extends AbstractRouter implements Comparable condition, URL url, URL param, Invocation invocation) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java index 496a0dce12..3a04f88e60 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; @@ -58,10 +59,10 @@ public class ScriptRouter extends AbstractRouter { String type = url.getParameter(Constants.TYPE_KEY); this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); String rule = url.getParameterAndDecoded(Constants.RULE_KEY); - if (type == null || type.length() == 0) { + if (StringUtils.isEmpty(type)) { type = Constants.DEFAULT_SCRIPT_TYPE_KEY; } - if (rule == null || rule.length() == 0) { + if (StringUtils.isEmpty(rule)) { throw new IllegalStateException("route rule can not be empty. rule:" + rule); } ScriptEngine engine = engines.get(type); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index 21fe390ee6..d65371e1ab 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -181,7 +181,7 @@ public class TagRouter extends AbstractRouter implements Comparable, Con @Override public void notify(List> invokers) { - if (invokers == null || invokers.isEmpty()) { + if (CollectionUtils.isEmpty(invokers)) { return; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index 293d3bda15..009f4df442 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; @@ -103,7 +104,7 @@ public class MockClusterInvoker implements Invoker { Invoker minvoker; List> mockInvokers = selectMockInvoker(invocation); - if (mockInvokers == null || mockInvokers.isEmpty()) { + if (CollectionUtils.isEmpty(mockInvokers)) { minvoker = (Invoker) new MockInvoker(directory.getUrl()); } else { minvoker = mockInvokers.get(0); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java index 529d3feb91..e321e0a23c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java @@ -96,13 +96,13 @@ public class Parameters { public String getParameter(String key) { String value = parameters.get(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = parameters.get(Constants.HIDE_KEY_PREFIX + key); } - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key); } - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = parameters.get(Constants.HIDE_KEY_PREFIX + Constants.DEFAULT_KEY_PREFIX + key); } return value; @@ -110,7 +110,7 @@ public class Parameters { public String getParameter(String key, String defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value; @@ -118,7 +118,7 @@ public class Parameters { public int getIntParameter(String key) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return 0; } return Integer.parseInt(value); @@ -126,7 +126,7 @@ public class Parameters { public int getIntParameter(String key, int defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Integer.parseInt(value); @@ -137,7 +137,7 @@ public class Parameters { throw new IllegalArgumentException("defaultValue <= 0"); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } int i = Integer.parseInt(value); @@ -149,7 +149,7 @@ public class Parameters { public boolean getBooleanParameter(String key) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return false; } return Boolean.parseBoolean(value); @@ -157,7 +157,7 @@ public class Parameters { public boolean getBooleanParameter(String key, boolean defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Boolean.parseBoolean(value); @@ -170,10 +170,10 @@ public class Parameters { public String getMethodParameter(String method, String key) { String value = parameters.get(method + "." + key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = parameters.get(Constants.HIDE_KEY_PREFIX + method + "." + key); } - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return getParameter(key); } return value; @@ -181,7 +181,7 @@ public class Parameters { public String getMethodParameter(String method, String key, String defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value; @@ -189,7 +189,7 @@ public class Parameters { public int getMethodIntParameter(String method, String key) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return 0; } return Integer.parseInt(value); @@ -197,7 +197,7 @@ public class Parameters { public int getMethodIntParameter(String method, String key, int defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Integer.parseInt(value); @@ -208,7 +208,7 @@ public class Parameters { throw new IllegalArgumentException("defaultValue <= 0"); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } int i = Integer.parseInt(value); @@ -220,7 +220,7 @@ public class Parameters { public boolean getMethodBooleanParameter(String method, String key) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return false; } return Boolean.parseBoolean(value); @@ -228,7 +228,7 @@ public class Parameters { public boolean getMethodBooleanParameter(String method, String key, boolean defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Boolean.parseBoolean(value); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java index e5d8537ec4..cee9c86343 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java @@ -18,6 +18,7 @@ package org.apache.dubbo.common; import org.apache.dubbo.common.config.Configuration; import org.apache.dubbo.common.config.InmemoryConfiguration; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -70,7 +71,8 @@ import java.util.concurrent.ConcurrentHashMap; * @see java.net.URL * @see java.net.URI */ -public /**final**/ class URL implements Serializable { +public /**final**/ +class URL implements Serializable { private static final long serialVersionUID = -1985165475234910535L; @@ -149,8 +151,8 @@ public /**final**/ class URL implements Serializable { } public URL(String protocol, String username, String password, String host, int port, String path, Map parameters) { - if ((username == null || username.length() == 0) - && password != null && password.length() > 0) { + if (StringUtils.isEmpty(username) + && StringUtils.isNotEmpty(password)) { throw new IllegalArgumentException("Invalid url, password without username!"); } this.protocol = protocol; @@ -248,7 +250,7 @@ public /**final**/ class URL implements Serializable { // see https://howdoesinternetwork.com/2013/ipv6-zone-id // ignore } else { - port = Integer.parseInt(url.substring(i+1)); + port = Integer.parseInt(url.substring(i + 1)); url = url.substring(0, i); } } @@ -300,7 +302,7 @@ public /**final**/ class URL implements Serializable { } public static String encode(String value) { - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return ""; } try { @@ -311,7 +313,7 @@ public /**final**/ class URL implements Serializable { } public static String decode(String value) { - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return ""; } try { @@ -346,8 +348,8 @@ public /**final**/ class URL implements Serializable { } public String getAuthority() { - if ((username == null || username.length() == 0) - && (password == null || password.length() == 0)) { + if (StringUtils.isEmpty(username) + && StringUtils.isEmpty(parameter)) { return null; } return (username == null ? "" : username) @@ -364,7 +366,7 @@ public /**final**/ class URL implements Serializable { /** * Fetch IP address for this URL. - * + *

* Pls. note that IP should be used instead of Host when to compare with socket's address or to search in a map * which use address as its key. * @@ -413,7 +415,7 @@ public /**final**/ class URL implements Serializable { public String getBackupAddress(int defaultPort) { StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort)); String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]); - if (backups != null && backups.length > 0) { + if (ArrayUtils.isNotEmpty(backups)) { for (String backup : backups) { address.append(","); address.append(appendDefaultPort(backup, defaultPort)); @@ -476,7 +478,7 @@ public /**final**/ class URL implements Serializable { public String getParameter(String key) { String value = parameters.get(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key); } return value; @@ -484,7 +486,7 @@ public /**final**/ class URL implements Serializable { public String getParameter(String key, String defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value; @@ -492,7 +494,7 @@ public /**final**/ class URL implements Serializable { public String[] getParameter(String key, String[] defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Constants.COMMA_SPLIT_PATTERN.split(value); @@ -518,7 +520,7 @@ public /**final**/ class URL implements Serializable { return u; } String value = getParameterAndDecoded(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return null; } u = URL.valueOf(value); @@ -532,7 +534,7 @@ public /**final**/ class URL implements Serializable { return n.doubleValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } double d = Double.parseDouble(value); @@ -546,7 +548,7 @@ public /**final**/ class URL implements Serializable { return n.floatValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } float f = Float.parseFloat(value); @@ -560,7 +562,7 @@ public /**final**/ class URL implements Serializable { return n.longValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } long l = Long.parseLong(value); @@ -574,7 +576,7 @@ public /**final**/ class URL implements Serializable { return n.intValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } int i = Integer.parseInt(value); @@ -588,7 +590,7 @@ public /**final**/ class URL implements Serializable { return n.shortValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } short s = Short.parseShort(value); @@ -602,7 +604,7 @@ public /**final**/ class URL implements Serializable { return n.byteValue(); } String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } byte b = Byte.parseByte(value); @@ -678,7 +680,7 @@ public /**final**/ class URL implements Serializable { public char getParameter(String key, char defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value.charAt(0); @@ -686,7 +688,7 @@ public /**final**/ class URL implements Serializable { public boolean getParameter(String key, boolean defaultValue) { String value = getParameter(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Boolean.parseBoolean(value); @@ -707,7 +709,7 @@ public /**final**/ class URL implements Serializable { public String getMethodParameter(String method, String key) { String value = parameters.get(method + "." + key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return getParameter(key); } return value; @@ -715,7 +717,7 @@ public /**final**/ class URL implements Serializable { public String getMethodParameter(String method, String key, String defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value; @@ -728,7 +730,7 @@ public /**final**/ class URL implements Serializable { return n.intValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } double d = Double.parseDouble(value); @@ -743,7 +745,7 @@ public /**final**/ class URL implements Serializable { return n.intValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } float f = Float.parseFloat(value); @@ -758,7 +760,7 @@ public /**final**/ class URL implements Serializable { return n.intValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } long l = Long.parseLong(value); @@ -773,7 +775,7 @@ public /**final**/ class URL implements Serializable { return n.intValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } int i = Integer.parseInt(value); @@ -788,7 +790,7 @@ public /**final**/ class URL implements Serializable { return n.shortValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } short s = Short.parseShort(value); @@ -803,7 +805,7 @@ public /**final**/ class URL implements Serializable { return n.byteValue(); } String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } byte b = Byte.parseByte(value); @@ -879,7 +881,7 @@ public /**final**/ class URL implements Serializable { public char getMethodParameter(String method, String key, char defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value.charAt(0); @@ -887,7 +889,7 @@ public /**final**/ class URL implements Serializable { public boolean getMethodParameter(String method, String key, boolean defaultValue) { String value = getMethodParameter(method, key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return Boolean.parseBoolean(value); @@ -925,7 +927,7 @@ public /**final**/ class URL implements Serializable { } public URL addParameterAndEncoded(String key, String value) { - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return this; } return addParameter(key, encode(value)); @@ -985,8 +987,8 @@ public /**final**/ class URL implements Serializable { } public URL addParameter(String key, String value) { - if (key == null || key.length() == 0 - || value == null || value.length() == 0) { + if (StringUtils.isEmpty(key) + || StringUtils.isEmpty(value)) { return this; } // if value doesn't change, return immediately @@ -1000,8 +1002,8 @@ public /**final**/ class URL implements Serializable { } public URL addParameterIfAbsent(String key, String value) { - if (key == null || key.length() == 0 - || value == null || value.length() == 0) { + if (StringUtils.isEmpty(key) + || StringUtils.isEmpty(value)) { return this; } if (hasParameter(key)) { @@ -1019,7 +1021,7 @@ public /**final**/ class URL implements Serializable { * @return A new URL */ public URL addParameters(Map parameters) { - if (parameters == null || parameters.size() == 0) { + if (CollectionUtils.isEmptyMap(parameters)) { return this; } @@ -1049,7 +1051,7 @@ public /**final**/ class URL implements Serializable { } public URL addParametersIfAbsent(Map parameters) { - if (parameters == null || parameters.size() == 0) { + if (CollectionUtils.isEmptyMap(parameters)) { return this; } Map map = new HashMap(parameters); @@ -1073,21 +1075,21 @@ public /**final**/ class URL implements Serializable { } public URL addParameterString(String query) { - if (query == null || query.length() == 0) { + if (StringUtils.isEmpty(query)) { return this; } return addParameters(StringUtils.parseQueryString(query)); } public URL removeParameter(String key) { - if (key == null || key.length() == 0) { + if (StringUtils.isEmpty(key)) { return this; } return removeParameters(key); } public URL removeParameters(Collection keys) { - if (keys == null || keys.isEmpty()) { + if (CollectionUtils.isEmpty(keys)) { return this; } return removeParameters(keys.toArray(new String[0])); @@ -1204,8 +1206,8 @@ public /**final**/ class URL implements Serializable { } private void buildParameters(StringBuilder buf, boolean concat, String[] parameters) { - if (getParameters() != null && getParameters().size() > 0) { - List includes = (parameters == null || parameters.length == 0 ? null : Arrays.asList(parameters)); + if (CollectionUtils.isNotEmptyMap(getParameters())) { + List includes = (ArrayUtils.isEmpty(parameters) ? null : Arrays.asList(parameters)); boolean first = true; for (Map.Entry entry : new TreeMap(getParameters()).entrySet()) { if (entry.getKey() != null && entry.getKey().length() > 0 @@ -1232,11 +1234,11 @@ public /**final**/ class URL implements Serializable { private String buildString(boolean appendUser, boolean appendParameter, boolean useIP, boolean useService, String... parameters) { StringBuilder buf = new StringBuilder(); - if (protocol != null && protocol.length() > 0) { + if (StringUtils.isNotEmpty(protocol)) { buf.append(protocol); buf.append("://"); } - if (appendUser && username != null && username.length() > 0) { + if (appendUser && StringUtils.isNotEmpty(username)) { buf.append(username); if (password != null && password.length() > 0) { buf.append(":"); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java index 9e5893fc76..7f859fbb62 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java @@ -19,6 +19,7 @@ package org.apache.dubbo.common; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ClassHelper; +import org.apache.dubbo.common.utils.StringUtils; import java.net.URL; import java.security.CodeSource; @@ -63,7 +64,7 @@ public final class Version { } public static boolean isSupportResponseAttachment(String version) { - if (version == null || version.length() == 0) { + if (StringUtils.isEmpty(version)) { return false; } // for previous dubbo version(2.0.10/020010~2.6.2/020602), this version is the jar's version, so they need to be ignore @@ -124,10 +125,10 @@ public final class Version { try { // find version info from MANIFEST.MF first String version = cls.getPackage().getImplementationVersion(); - if (version == null || version.length() == 0) { + if (StringUtils.isEmpty(version)) { version = cls.getPackage().getSpecificationVersion(); } - if (version == null || version.length() == 0) { + if (StringUtils.isEmpty(version)) { // guess version fro jar file name if nothing's found from MANIFEST.MF CodeSource codeSource = cls.getProtectionDomain().getCodeSource(); if (codeSource == null) { @@ -157,7 +158,7 @@ public final class Version { } } // return default version if no version info is found - return version == null || version.length() == 0 ? defaultVersion : version; + return StringUtils.isEmpty(version) ? defaultVersion : version; } catch (Throwable e) { // return default version when any exception is thrown logger.error("return default version, ignore exception " + e.getMessage(), e); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java index c044c7b297..40ae8856cf 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.bytecode; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.ClassHelper; import org.apache.dubbo.common.utils.ReflectUtils; @@ -29,6 +30,7 @@ import javassist.CtNewConstructor; import javassist.CtNewMethod; import javassist.LoaderClassPath; import javassist.NotFoundException; +import org.apache.dubbo.common.utils.StringUtils; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -165,7 +167,7 @@ public final class ClassGenerator { StringBuilder sb = new StringBuilder(); sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(type)).append(' '); sb.append(name); - if (def != null && def.length() > 0) { + if (StringUtils.isNotEmpty(def)) { sb.append('='); sb.append(def); } @@ -198,7 +200,7 @@ public final class ClassGenerator { sb.append(" arg").append(i); } sb.append(')'); - if (ets != null && ets.length > 0) { + if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { @@ -250,7 +252,7 @@ public final class ClassGenerator { sb.append(" arg").append(i); } sb.append(')'); - if (ets != null && ets.length > 0) { + if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java index 133ece552b..5d3cdad041 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.common.compiler.support; +import org.apache.dubbo.common.utils.StringUtils; + import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Array; @@ -291,7 +293,7 @@ public class ClassUtils { } public static boolean isBeforeJava5(String javaVersion) { - return (javaVersion == null || javaVersion.length() == 0 || "1.0".equals(javaVersion) + return (StringUtils.isEmpty(javaVersion) || "1.0".equals(javaVersion) || "1.1".equals(javaVersion) || "1.2".equals(javaVersion) || "1.3".equals(javaVersion) || "1.4".equals(javaVersion)); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 578ff65ddf..42fa01bb25 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -27,7 +27,7 @@ import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.Holder; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; - +import org.apache.dubbo.common.utils.CollectionUtils; import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.reflect.Method; @@ -187,7 +187,7 @@ public class ExtensionLoader { */ public List getActivateExtension(URL url, String key, String group) { String value = url.getParameter(key); - return getActivateExtension(url, value == null || value.length() == 0 ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group); + return getActivateExtension(url, StringUtils.isEmpty(value) ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group); } /** @@ -253,7 +253,7 @@ public class ExtensionLoader { } private boolean isMatchGroup(String group, String[] groups) { - if (group == null || group.length() == 0) { + if (StringUtils.isEmpty(group)) { return true; } if (groups != null && groups.length > 0) { @@ -293,7 +293,7 @@ public class ExtensionLoader { */ @SuppressWarnings("unchecked") public T getLoadedExtension(String name) { - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { throw new IllegalArgumentException("Extension name == null"); } Holder holder = cachedInstances.get(name); @@ -325,7 +325,7 @@ public class ExtensionLoader { */ @SuppressWarnings("unchecked") public T getExtension(String name) { - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { throw new IllegalArgumentException("Extension name == null"); } if ("true".equals(name)) { @@ -362,7 +362,7 @@ public class ExtensionLoader { } public boolean hasExtension(String name) { - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { throw new IllegalArgumentException("Extension name == null"); } Class c = this.getExtensionClass(name); @@ -528,7 +528,7 @@ public class ExtensionLoader { } injectExtension(instance); Set> wrapperClasses = cachedWrapperClasses; - if (wrapperClasses != null && !wrapperClasses.isEmpty()) { + if (CollectionUtils.isNotEmpty(wrapperClasses)) { for (Class wrapperClass : wrapperClasses) { instance = injectExtension((T) wrapperClass.getConstructor(type).newInstance(instance)); } @@ -709,7 +709,7 @@ public class ExtensionLoader { wrappers.add(clazz); } else { clazz.getConstructor(); - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { name = findAnnotationName(clazz); if (name.length() == 0) { throw new IllegalStateException("No such extension name for the class " + clazz.getName() + " in the config " + resourceURL); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java index 37271087c9..40baecdd2d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java @@ -55,7 +55,7 @@ public class CollectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static List sort(List list) { - if (list != null && !list.isEmpty()) { + if (isNotEmpty(list)) { Collections.sort((List) list); } return list; @@ -120,7 +120,7 @@ public class CollectionUtils { for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { list.add(key); } else { list.add(key + separator + value); @@ -206,7 +206,15 @@ public class CollectionUtils { } public static boolean isNotEmpty(Collection collection) { - return collection != null && !collection.isEmpty(); + return !isEmpty(collection); + } + + public static boolean isEmptyMap(Map map) { + return map == null || map.size() == 0; + } + + public static boolean isNotEmptyMap(Map map) { + return !isEmptyMap(map); } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java index 93013569c4..0c68512c20 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java @@ -50,7 +50,7 @@ public class ConfigUtils { } public static boolean isEmpty(String value) { - return value == null || value.length() == 0 + return StringUtils.isEmpty(value) || "false".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value) || "null".equalsIgnoreCase(value) @@ -190,7 +190,7 @@ public class ConfigUtils { */ public static String getSystemProperty(String key) { String value = System.getenv(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { value = System.getProperty(key); } return value; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java index f93bc5a5f3..5c157c5a03 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java @@ -126,7 +126,7 @@ public class UrlUtils { String defaultValue = entry.getValue(); if (defaultValue != null && defaultValue.length() > 0) { String value = parameters.get(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { changed = true; parameters.put(key, defaultValue); } @@ -318,7 +318,7 @@ public class UrlUtils { //compatible for dubbo-2.0.0 public static List revertForbid(List forbid, Set subscribed) { - if (forbid != null && !forbid.isEmpty()) { + if (CollectionUtils.isNotEmpty(forbid)) { List newForbid = new ArrayList(); for (String serviceName : forbid) { if (!serviceName.contains(":") && !serviceName.contains("/")) { @@ -410,12 +410,10 @@ public class UrlUtils { if ("*".equals(pattern)) { return true; } - if ((pattern == null || pattern.length() == 0) - && (value == null || value.length() == 0)) { + if (StringUtils.isEmpty(pattern) && StringUtils.isEmpty(value)) { return true; } - if ((pattern == null || pattern.length() == 0) - || (value == null || value.length() == 0)) { + if (StringUtils.isEmpty(pattern) || StringUtils.isEmpty(value)) { return false; } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java index b409cee4be..ecc3f46ee3 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java @@ -774,7 +774,7 @@ public class PojoUtilsTest { } public void setList(List list) { - if (list != null && !list.isEmpty()) { + if (CollectionUtils.isNotEmpty(list)) { this.list.addAll(list); } } @@ -784,7 +784,7 @@ public class PojoUtilsTest { } public void setChildren(Map children) { - if (children != null && !children.isEmpty()) { + if (CollectionUtils.isNotEmptyMap(children)) { this.children.putAll(children); } } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/URL.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/URL.java index 76b09f43db..255481f82a 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/URL.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/URL.java @@ -18,6 +18,7 @@ package com.alibaba.dubbo.common; import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.StringUtils; import java.net.InetSocketAddress; import java.util.Collection; @@ -403,7 +404,7 @@ public class URL extends org.apache.dubbo.common.URL { @Override public URL addParameterAndEncoded(String key, String value) { - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return this; } return addParameter(key, encode(value)); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 5921abc3d3..00c6950450 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -359,7 +359,7 @@ public abstract class AbstractConfig implements Serializable { } protected static void checkParameterName(Map parameters) { - if (parameters == null || parameters.size() == 0) { + if (CollectionUtils.isEmptyMap(parameters)) { return; } for (Map.Entry entry : parameters.entrySet()) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 3dbf40ceff..a4c24f66ed 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.metadata.integration.MetadataReportService; import org.apache.dubbo.monitor.MonitorFactory; @@ -242,7 +243,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { checkRegistry(); checkRegistryDataConfig(); List registryList = new ArrayList(); - if (registries != null && !registries.isEmpty()) { + if (CollectionUtils.isNotEmpty(registries)) { Map registryDataConfigurationMap = new HashMap<>(4); appendParameters(registryDataConfigurationMap, registryDataConfig); for (RegistryConfig config : registries) { @@ -291,7 +292,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { appendRuntimeParameters(map); //set ip String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); - if (hostToRegistry == null || hostToRegistry.length() == 0) { + if (StringUtils.isEmpty(hostToRegistry)) { hostToRegistry = NetUtils.getLocalHost(); } else if (NetUtils.isInvalidLocalHost(hostToRegistry)) { throw new IllegalArgumentException("Specified invalid registry ip from property:" + @@ -332,7 +333,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { private URL loadMetadataReporterURL(boolean provider) { this.checkApplication(); String address = metadataReportConfig.getAddress(); - if (address == null || address.length() == 0) { + if (StringUtils.isEmpty(address)) { return null; } Map map = new HashMap(); @@ -367,13 +368,13 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!"); } // check if methods exist in the remote service interface - if (methods != null && !methods.isEmpty()) { + if (CollectionUtils.isNotEmpty(methods)) { for (MethodConfig methodBean : methods) { methodBean.setService(interfaceClass.getName()); methodBean.setServiceId(this.getId()); methodBean.refresh(); String methodName = methodBean.getName(); - if (methodName == null || methodName.length() == 0) { + if (StringUtils.isEmpty(methodName)) { throw new IllegalStateException(" name attribute is required! Please check: " + "" + ""); @@ -472,7 +473,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } private void convertRegistryIdsToRegistries() { - if (StringUtils.isEmpty(registryIds) && (registries == null || registries.isEmpty())) { + if (StringUtils.isEmpty(registryIds) && CollectionUtils.isEmpty(registries)) { Set configedRegistries = new HashSet<>(); configedRegistries.addAll(getSubProperties(Environment.getInstance().getExternalConfigurationMap(), Constants.REGISTRIES_SUFFIX)); @@ -483,13 +484,13 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } if (StringUtils.isEmpty(registryIds)) { - if (registries == null || registries.isEmpty()) { + if (CollectionUtils.isEmpty(registries)) { registries = new ArrayList<>(); registries.add(new RegistryConfig()); } } else { String[] arr = Constants.COMMA_SPLIT_PATTERN.split(registryIds); - if (registries == null || registries.isEmpty()) { + if (CollectionUtils.isEmpty(registries)) { registries = new ArrayList<>(); } Arrays.stream(arr).forEach(id -> { @@ -663,7 +664,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } public RegistryConfig getRegistry() { - return registries == null || registries.isEmpty() ? null : registries.get(0); + return CollectionUtils.isEmpty(registries) ? null : registries.get(0); } public void setRegistry(RegistryConfig registry) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java index ed8ba4a96d..74560a143e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.rpc.ExporterListener; @@ -203,7 +204,7 @@ public abstract class AbstractServiceConfig extends AbstractInterfaceConfig { } public ProtocolConfig getProtocol() { - return protocols == null || protocols.isEmpty() ? null : protocols.get(0); + return CollectionUtils.isEmpty(protocols) ? null : protocols.get(0); } public void setProtocol(ProtocolConfig protocol) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index fa184c8348..d73e3e209e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -19,6 +19,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.compiler.support.AdaptiveCompiler; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; @@ -202,7 +203,7 @@ public class ApplicationConfig extends AbstractConfig { } public RegistryConfig getRegistry() { - return registries == null || registries.isEmpty() ? null : registries.get(0); + return CollectionUtils.isEmpty(registries) ? null : registries.get(0); } public void setRegistry(RegistryConfig registry) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ModuleConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ModuleConfig.java index 36168096cf..b47c35c479 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ModuleConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ModuleConfig.java @@ -17,6 +17,8 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; import java.util.ArrayList; @@ -81,7 +83,7 @@ public class ModuleConfig extends AbstractConfig { public void setName(String name) { checkName(Constants.NAME, name); this.name = name; - if (id == null || id.length() == 0) { + if (StringUtils.isEmpty(id)) { id = name; } } @@ -114,7 +116,7 @@ public class ModuleConfig extends AbstractConfig { } public RegistryConfig getRegistry() { - return registries == null || registries.isEmpty() ? null : registries.get(0); + return CollectionUtils.isEmpty(registries) ? null : registries.get(0); } public void setRegistry(RegistryConfig registry) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 4b30bfe101..55020268f2 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.ClassHelper; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.metadata.integration.MetadataReportService; @@ -191,7 +192,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { * Check each config modules are created properly and override their properties if necessary. */ public void checkAndUpdateSubConfigs() { - if (interfaceName == null || interfaceName.length() == 0) { + if (StringUtils.isEmpty(interfaceName)) { throw new IllegalStateException(" interface not allow null!"); } // get consumer's global configuration @@ -286,7 +287,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { appendParameters(map, consumer, Constants.DEFAULT_KEY); appendParameters(map, this); Map attributes = null; - if (methods != null && !methods.isEmpty()) { + if (CollectionUtils.isNotEmpty(methods)) { attributes = new HashMap(); for (MethodConfig methodConfig : methods) { appendParameters(map, methodConfig, methodConfig.getName()); @@ -302,7 +303,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { } String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); - if (hostToRegistry == null || hostToRegistry.length() == 0) { + if (StringUtils.isEmpty(hostToRegistry)) { hostToRegistry = NetUtils.getLocalHost(); } else if (isInvalidLocalHost(hostToRegistry)) { throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry); @@ -342,7 +343,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { if (us != null && us.length > 0) { for (String u : us) { URL url = URL.valueOf(u); - if (url.getPath() == null || url.getPath().length() == 0) { + if (StringUtils.isEmpty(url.getPath())) { url = url.setPath(interfaceName); } if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { @@ -354,7 +355,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { } } else { // assemble URL from register center's configuration List us = loadRegistries(false); - if (us != null && !us.isEmpty()) { + if (CollectionUtils.isNotEmpty(us)) { for (URL u : us) { URL monitorUrl = loadMonitor(u); if (monitorUrl != null) { @@ -493,7 +494,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { public void setInterface(String interfaceName) { this.interfaceName = interfaceName; - if (id == null || id.length() == 0) { + if (StringUtils.isEmpty(id)) { id = interfaceName; } } @@ -561,7 +562,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { buf.append(group).append("/"); } buf.append(interfaceName); - if (version != null && version.length() > 0) { + if (StringUtils.isNotEmpty(version)) { buf.append(":").append(version); } return buf.toString(); @@ -576,9 +577,9 @@ public class ReferenceConfig extends AbstractReferenceConfig { private void resolveFile() { String resolve = System.getProperty(interfaceName); String resolveFile = null; - if (resolve == null || resolve.length() == 0) { + if (StringUtils.isEmpty(resolve)) { resolveFile = System.getProperty("dubbo.resolve.file"); - if (resolveFile == null || resolveFile.length() == 0) { + if (StringUtils.isEmpty(resolveFile)) { File userResolveFile = new File(new File(System.getProperty("user.home")), "dubbo-resolve.properties"); if (userResolveFile.exists()) { resolveFile = userResolveFile.getAbsolutePath(); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index fe870db1f2..8e6bccc421 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.ClassHelper; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker; import org.apache.dubbo.config.support.Parameter; @@ -173,7 +174,7 @@ public class ServiceConfig extends AbstractServiceConfig { @Deprecated private static List convertProviderToProtocol(List providers) { - if (providers == null || providers.isEmpty()) { + if (CollectionUtils.isEmpty(providers)) { return null; } List protocols = new ArrayList(providers.size()); @@ -185,7 +186,7 @@ public class ServiceConfig extends AbstractServiceConfig { @Deprecated private static List convertProtocolToProvider(List protocols) { - if (protocols == null || protocols.isEmpty()) { + if (CollectionUtils.isEmpty(protocols)) { return null; } List providers = new ArrayList(protocols.size()); @@ -277,7 +278,7 @@ public class ServiceConfig extends AbstractServiceConfig { checkMetadataReport(); checkRegistryDataConfig(); - if (interfaceName == null || interfaceName.length() == 0) { + if (StringUtils.isEmpty(interfaceName)) { throw new IllegalStateException(" interface not allow null!"); } @@ -360,7 +361,7 @@ public class ServiceConfig extends AbstractServiceConfig { } exported = true; - if (path == null || path.length() == 0) { + if (StringUtils.isEmpty(path)) { path = interfaceName; } ProviderModel providerModel = new ProviderModel(getUniqueServiceName(), ref, interfaceClass); @@ -410,7 +411,7 @@ public class ServiceConfig extends AbstractServiceConfig { private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List registryURLs) { String name = protocolConfig.getName(); - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { name = Constants.DUBBO; } @@ -422,7 +423,7 @@ public class ServiceConfig extends AbstractServiceConfig { appendParameters(map, provider, Constants.DEFAULT_KEY); appendParameters(map, protocolConfig); appendParameters(map, this); - if (methods != null && !methods.isEmpty()) { + if (CollectionUtils.isNotEmpty(methods)) { for (MethodConfig method : methods) { appendParameters(map, method, method.getName()); String retryKey = method.getName() + ".retry"; @@ -433,7 +434,7 @@ public class ServiceConfig extends AbstractServiceConfig { } } List arguments = method.getArguments(); - if (arguments != null && !arguments.isEmpty()) { + if (CollectionUtils.isNotEmpty(arguments)) { for (ArgumentConfig argument : arguments) { // convert argument type if (argument.getType() != null && argument.getType().length() > 0) { @@ -508,13 +509,13 @@ public class ServiceConfig extends AbstractServiceConfig { } // export service String contextPath = protocolConfig.getContextpath(); - if ((contextPath == null || contextPath.length() == 0) && provider != null) { + if (StringUtils.isEmpty(contextPath) && provider != null) { contextPath = provider.getContextpath(); } String host = this.findConfigedHosts(protocolConfig, registryURLs, map); Integer port = this.findConfigedPorts(protocolConfig, name, map); - URL url = new URL(name, host, port, (contextPath == null || contextPath.length() == 0 ? "" : contextPath + "/") + path, map); + URL url = new URL(name, host, port, (StringUtils.isEmpty(contextPath) ? "" : contextPath + "/") + path, map); if (ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class) .hasExtension(url.getProtocol())) { @@ -535,7 +536,7 @@ public class ServiceConfig extends AbstractServiceConfig { if (logger.isInfoEnabled()) { logger.info("Export dubbo service " + interfaceClass.getName() + " to url " + url); } - if (registryURLs != null && !registryURLs.isEmpty()) { + if (CollectionUtils.isNotEmpty(registryURLs)) { for (URL registryURL : registryURLs) { url = url.addParameterIfAbsent(Constants.DYNAMIC_KEY, registryURL.getParameter(Constants.DYNAMIC_KEY)); URL monitorUrl = loadMonitor(registryURL); @@ -651,9 +652,9 @@ public class ServiceConfig extends AbstractServiceConfig { } // if bind ip is not found in environment, keep looking up - if (hostToBind == null || hostToBind.length() == 0) { + if (StringUtils.isEmpty(hostToBind)) { hostToBind = protocolConfig.getHost(); - if (provider != null && (hostToBind == null || hostToBind.length() == 0)) { + if (provider != null && StringUtils.isEmpty(hostToBind)) { hostToBind = provider.getHost(); } if (isInvalidLocalHost(hostToBind)) { @@ -664,7 +665,7 @@ public class ServiceConfig extends AbstractServiceConfig { logger.warn(e.getMessage(), e); } if (isInvalidLocalHost(hostToBind)) { - if (registryURLs != null && !registryURLs.isEmpty()) { + if (CollectionUtils.isNotEmpty(registryURLs)) { for (URL registryURL : registryURLs) { if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter("registry"))) { // skip multicast registry since we cannot connect to it via Socket @@ -701,7 +702,7 @@ public class ServiceConfig extends AbstractServiceConfig { String hostToRegistry = getValueFromConfig(protocolConfig, Constants.DUBBO_IP_TO_REGISTRY); if (hostToRegistry != null && hostToRegistry.length() > 0 && isInvalidLocalHost(hostToRegistry)) { throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry); - } else if (hostToRegistry == null || hostToRegistry.length() == 0) { + } else if (StringUtils.isEmpty(hostToRegistry)) { // bind ip is used as registry ip by default hostToRegistry = hostToBind; } @@ -778,7 +779,7 @@ public class ServiceConfig extends AbstractServiceConfig { private String getValueFromConfig(ProtocolConfig protocolConfig, String key) { String protocolPrefix = protocolConfig.getName().toUpperCase() + "_"; String port = ConfigUtils.getSystemProperty(protocolPrefix + key); - if (port == null || port.length() == 0) { + if (StringUtils.isEmpty(port)) { port = ConfigUtils.getSystemProperty(key); } return port; @@ -792,7 +793,7 @@ public class ServiceConfig extends AbstractServiceConfig { } private void checkProtocol() { - if ((protocols == null || protocols.isEmpty()) && provider != null) { + if (CollectionUtils.isEmpty(protocols) && provider != null) { setProtocols(provider.getProtocols()); } @@ -811,7 +812,7 @@ public class ServiceConfig extends AbstractServiceConfig { } private void convertProtocolIdsToProtocols() { - if (StringUtils.isEmpty(protocolIds) && (protocols == null || protocols.isEmpty())) { + if (StringUtils.isEmpty(protocolIds) && CollectionUtils.isEmpty(protocols)) { List configedProtocols = new ArrayList<>(); configedProtocols.addAll(getSubProperties(Environment.getInstance() .getExternalConfigurationMap(), Constants.PROTOCOLS_SUFFIX)); @@ -822,13 +823,13 @@ public class ServiceConfig extends AbstractServiceConfig { } if (StringUtils.isEmpty(protocolIds)) { - if (protocols == null || protocols.isEmpty()) { + if (CollectionUtils.isEmpty(protocols)) { protocols = new ArrayList<>(); protocols.add(new ProtocolConfig()); } } else { String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds); - if (protocols == null || protocols.isEmpty()) { + if (CollectionUtils.isEmpty(protocols)) { protocols = new ArrayList<>(); } Arrays.stream(arr).forEach(id -> { @@ -886,7 +887,7 @@ public class ServiceConfig extends AbstractServiceConfig { public void setInterface(String interfaceName) { this.interfaceName = interfaceName; - if (id == null || id.length() == 0) { + if (StringUtils.isEmpty(id)) { id = interfaceName; } } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java index 9af02a1e16..8593067725 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java @@ -19,8 +19,10 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.AbstractConfig; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConsumerConfig; @@ -74,7 +76,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be public void setPackage(String annotationPackage) { this.annotationPackage = annotationPackage; - this.annotationPackages = (annotationPackage == null || annotationPackage.length() == 0) ? null + this.annotationPackages = (StringUtils.isEmpty(annotationPackage)) ? null : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage); } @@ -86,7 +88,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - if (annotationPackage == null || annotationPackage.length() == 0) { + if (StringUtils.isEmpty(annotationPackage)) { return; } if (beanFactory instanceof BeanDefinitionRegistry) { @@ -306,7 +308,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be } private boolean isMatchPackage(Object bean) { - if (annotationPackages == null || annotationPackages.length == 0) { + if (ArrayUtils.isEmpty(annotationPackages)) { return true; } String beanClassName = bean.getClass().getName(); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java index 1762d8fb87..e497d4ba15 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.config.spring; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConfigCenterConfig; @@ -78,7 +79,7 @@ public class ConfigCenterBean extends ConfigCenterConfig implements Initializing if ((getRegistry() == null)) { List registryConfigs = new ArrayList<>(); - if (getApplication() != null && getApplication().getRegistries() != null && !getApplication().getRegistries().isEmpty()) { + if (getApplication() != null && CollectionUtils.isNotEmpty(getApplication().getRegistries())) { registryConfigs = getApplication().getRegistries(); } else { Map registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java index fd7025a990..3a3e419beb 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConsumerConfig; @@ -151,9 +152,9 @@ public class ReferenceBean extends ReferenceConfig implements FactoryBean, } } - if ((getRegistries() == null || getRegistries().isEmpty()) - && (getConsumer() == null || getConsumer().getRegistries() == null || getConsumer().getRegistries().isEmpty()) - && (getApplication() == null || getApplication().getRegistries() == null || getApplication().getRegistries().isEmpty())) { + if (CollectionUtils.isEmpty(getRegistries()) + && (getConsumer() == null || CollectionUtils.isEmpty(getConsumer().getRegistries())) + && (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) { Map registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false); if (registryConfigMap != null && registryConfigMap.size() > 0) { List registryConfigs = new ArrayList<>(); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java index cb6d097915..c72abf9446 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.MetadataReportConfig; @@ -112,7 +113,7 @@ public class ServiceBean extends ServiceConfig implements InitializingBean Map providerConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProviderConfig.class, false, false); if (providerConfigMap != null && providerConfigMap.size() > 0) { Map protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); - if ((protocolConfigMap == null || protocolConfigMap.size() == 0) + if (CollectionUtils.isEmptyMap(protocolConfigMap) && providerConfigMap.size() > 1) { // backward compatibility List providerConfigs = new ArrayList(); for (ProviderConfig config : providerConfigMap.values()) { @@ -185,11 +186,11 @@ public class ServiceBean extends ServiceConfig implements InitializingBean } } - if ((getRegistries() == null || getRegistries().isEmpty()) - && (getProvider() == null || getProvider().getRegistries() == null || getProvider().getRegistries().isEmpty()) - && (getApplication() == null || getApplication().getRegistries() == null || getApplication().getRegistries().isEmpty())) { + if ((CollectionUtils.isEmpty(getRegistries())) + && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getRegistries())) + && (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) { Map registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false); - if (registryConfigMap != null && registryConfigMap.size() > 0) { + if (CollectionUtils.isNotEmptyMap(registryConfigMap)) { List registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { @@ -255,8 +256,8 @@ public class ServiceBean extends ServiceConfig implements InitializingBean } } - if ((getProtocols() == null || getProtocols().isEmpty()) - && (getProvider() == null || getProvider().getProtocols() == null || getProvider().getProtocols().isEmpty())) { + if (CollectionUtils.isEmpty(getProtocols()) + && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getProtocols()))) { Map protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); if (protocolConfigMap != null && protocolConfigMap.size() > 0) { List protocolConfigs = new ArrayList(); @@ -282,9 +283,9 @@ public class ServiceBean extends ServiceConfig implements InitializingBean } } } - if (getPath() == null || getPath().length() == 0) { - if (beanName != null && beanName.length() > 0 - && getInterface() != null && getInterface().length() > 0 + if (StringUtils.isEmpty(getPath())) { + if (StringUtils.isNotEmpty(beanName) + && StringUtils.isNotEmpty(getInterface()) && beanName.startsWith(getInterface())) { setPath(beanName); } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java index 4d8f0bdd29..926c15a011 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.spring.ReferenceBean; @@ -582,7 +583,7 @@ public class ReferenceAnnotationBeanPostProcessor extends InstantiationAwareBean } private String toPlainString(String[] array) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return ""; } StringBuilder buffer = new StringBuilder(); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java index 9426f70ed2..a2f5499258 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java @@ -75,16 +75,16 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { beanDefinition.setBeanClass(beanClass); beanDefinition.setLazyInit(false); String id = element.getAttribute("id"); - if ((id == null || id.length() == 0) && required) { + if (StringUtils.isEmpty(id) && required) { String generatedBeanName = element.getAttribute("name"); - if (generatedBeanName == null || generatedBeanName.length() == 0) { + if (StringUtils.isEmpty(generatedBeanName)) { if (ProtocolConfig.class.equals(beanClass)) { generatedBeanName = "dubbo"; } else { generatedBeanName = element.getAttribute("interface"); } } - if (generatedBeanName == null || generatedBeanName.length() == 0) { + if (StringUtils.isEmpty(generatedBeanName)) { generatedBeanName = beanClass.getName(); } id = generatedBeanName; @@ -258,7 +258,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { if (first) { first = false; String isDefault = element.getAttribute("default"); - if (isDefault == null || isDefault.length() == 0) { + if (StringUtils.isEmpty(isDefault)) { beanDefinition.getPropertyValues().addPropertyValue("default", "false"); } } @@ -335,7 +335,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { Element element = (Element) node; if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) { String methodName = element.getAttribute("name"); - if (methodName == null || methodName.length() == 0) { + if (StringUtils.isEmpty(methodName)) { throw new IllegalStateException(" name attribute == null"); } if (methods == null) { diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java index 5f268065b4..b777f63f23 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.status.Status; import org.apache.dubbo.common.status.StatusChecker; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.spring.extension.SpringExtensionFactory; import org.springframework.context.ApplicationContext; @@ -55,7 +56,7 @@ public class DataSourceStatusChecker implements StatusChecker { } Map dataSources = context.getBeansOfType(DataSource.class, false, false); - if (dataSources == null || dataSources.size() == 0) { + if (CollectionUtils.isEmptyMap(dataSources)) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.java index 3c273d3bb4..6aabdfacac 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.java @@ -19,6 +19,8 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.RegistryService; @@ -205,8 +207,8 @@ public abstract class AbstractRegistryService implements RegistryService { } protected final void notify(String service, List urls) { - if (service == null || service.length() == 0 - || urls == null || urls.size() == 0) { + if (StringUtils.isEmpty(service) + || CollectionUtils.isEmpty(urls)) { return; } doNotify(service, urls); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.java index eebd354e77..d90829d4a4 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.java @@ -19,6 +19,7 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; @@ -72,7 +73,7 @@ public class SimpleRegistryService extends AbstractRegistryService { } List urls = getRegistered().get(service); if ((RegistryService.class.getName() + ":0.0.0").equals(service) - && (urls == null || urls.size() == 0)) { + && CollectionUtils.isEmpty(urls)) { register(service, new URL("dubbo", NetUtils.getLocalHost(), RpcContext.getContext().getLocalPort(), diff --git a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java index 5462d5215c..eaf0c64a2a 100644 --- a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java +++ b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.ConfigUtils; import java.text.SimpleDateFormat; @@ -49,7 +50,7 @@ public class Main { public static void main(String[] args) { try { - if (args == null || args.length == 0) { + if (ArrayUtils.isEmpty(args)) { String config = ConfigUtils.getProperty(CONTAINER_KEY, loader.getDefaultExtensionName()); args = Constants.COMMA_SPLIT_PATTERN.split(config); } diff --git a/dubbo-container/dubbo-container-log4j/src/main/java/org/apache/dubbo/container/log4j/Log4jContainer.java b/dubbo-container/dubbo-container-log4j/src/main/java/org/apache/dubbo/container/log4j/Log4jContainer.java index 4b90cc2b2e..ed6594196f 100644 --- a/dubbo-container/dubbo-container-log4j/src/main/java/org/apache/dubbo/container/log4j/Log4jContainer.java +++ b/dubbo-container/dubbo-container-log4j/src/main/java/org/apache/dubbo/container/log4j/Log4jContainer.java @@ -17,6 +17,7 @@ package org.apache.dubbo.container.log4j; import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.container.Container; import org.apache.log4j.Appender; @@ -46,7 +47,7 @@ public class Log4jContainer implements Container { String file = ConfigurationUtils.getProperty(LOG4J_FILE); if (file != null && file.length() > 0) { String level = ConfigurationUtils.getProperty(LOG4J_LEVEL); - if (level == null || level.length() == 0) { + if (StringUtils.isEmpty(level)) { level = DEFAULT_LOG4J_LEVEL; } Properties properties = new Properties(); diff --git a/dubbo-container/dubbo-container-logback/src/main/java/org/apache/dubbo/container/logback/LogbackContainer.java b/dubbo-container/dubbo-container-logback/src/main/java/org/apache/dubbo/container/logback/LogbackContainer.java index 080b8ae6bc..452e181a53 100644 --- a/dubbo-container/dubbo-container-logback/src/main/java/org/apache/dubbo/container/logback/LogbackContainer.java +++ b/dubbo-container/dubbo-container-logback/src/main/java/org/apache/dubbo/container/logback/LogbackContainer.java @@ -47,7 +47,7 @@ public class LogbackContainer implements Container { String file = ConfigUtils.getProperty(LOGBACK_FILE); if (file != null && file.length() > 0) { String level = ConfigUtils.getProperty(LOGBACK_LEVEL); - if (level == null || level.length() == 0) { + if (StringUtils.isEmpty(level)) { level = DEFAULT_LOGBACK_LEVEL; } // maxHistory=0 Infinite history diff --git a/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java b/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java index c6ec474673..43c10fbb24 100644 --- a/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java +++ b/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java @@ -19,6 +19,7 @@ package org.apache.dubbo.container.spring; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConfigUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.container.Container; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -40,7 +41,7 @@ public class SpringContainer implements Container { @Override public void start() { String configPath = ConfigUtils.getProperty(SPRING_CONFIG); - if (configPath == null || configPath.length() == 0) { + if (StringUtils.isEmpty(configPath)) { configPath = DEFAULT_SPRING_CONFIG; } context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+")); diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java index 92e16423e3..4be16c84b3 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java @@ -18,6 +18,7 @@ package org.apache.dubbo.cache.support.jcache; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; import javax.cache.Cache; import javax.cache.CacheException; @@ -49,7 +50,7 @@ public class JCache implements org.apache.dubbo.cache.Cache { // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); - CachingProvider provider = type == null || type.length() == 0 ? Caching.getCachingProvider() : Caching.getCachingProvider(type); + CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type); CacheManager cacheManager = provider.getCacheManager(); Cache cache = cacheManager.getCache(key); if (cache == null) { diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java index 3a7dda1988..a21de3f5dc 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/JaketConfigurationUtils.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.metadata.definition.util; +import org.apache.dubbo.common.utils.StringUtils; + import java.io.InputStream; import java.util.Properties; @@ -36,17 +38,17 @@ public class JaketConfigurationUtils { try { props.load(inStream); String value = (String) props.get("included_interface_packages"); - if (value != null && !value.isEmpty()) { + if (StringUtils.isNotEmpty(value)) { includedInterfacePackages = value.split(","); } value = props.getProperty("included_type_packages"); - if (value != null && !value.isEmpty()) { + if (StringUtils.isNotEmpty(value)) { includedTypePackages = value.split(","); } value = props.getProperty("closed_types"); - if (value != null && !value.isEmpty()) { + if (StringUtils.isNotEmpty(value)) { closedTypes = value.split(","); } diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java index e563741630..1ac63e84fe 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java @@ -18,6 +18,7 @@ package org.apache.dubbo.monitor.dubbo; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.monitor.Monitor; import org.apache.dubbo.monitor.MonitorService; import org.apache.dubbo.monitor.support.AbstractMonitorFactory; @@ -45,11 +46,11 @@ public class DubboMonitorFactory extends AbstractMonitorFactory { @Override protected Monitor createMonitor(URL url) { url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo")); - if (url.getPath() == null || url.getPath().length() == 0) { + if (StringUtils.isEmpty(url.getPath())) { url = url.setPath(MonitorService.class.getName()); } String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY); - if (filter == null || filter.length() == 0) { + if (StringUtils.isEmpty(filter)) { filter = ""; } else { filter = filter + ","; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java index ce92d61282..30ba14b6fe 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java @@ -19,6 +19,7 @@ package org.apache.dubbo.qos.command.impl; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.qos.command.BaseCommand; import org.apache.dubbo.qos.command.CommandContext; import org.apache.dubbo.qos.command.annotation.Cmd; @@ -44,7 +45,7 @@ public class Online implements BaseCommand { public String execute(CommandContext commandContext, String[] args) { logger.info("receive online command"); String servicePattern = ".*"; - if (args != null && args.length > 0) { + if (ArrayUtils.isNotEmpty(args)) { servicePattern = args[0]; } diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java index ff49804b75..221a81c0d6 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java @@ -17,6 +17,7 @@ package org.apache.dubbo.qos.command; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.qos.command.annotation.Cmd; @@ -24,6 +25,6 @@ import org.apache.dubbo.qos.command.annotation.Cmd; public class GreetingCommand implements BaseCommand { @Override public String execute(CommandContext commandContext, String[] args) { - return args != null && args.length > 0 ? "greeting " + args[0] : "greeting"; + return ArrayUtils.isNotEmpty(args) ? "greeting " + args[0] : "greeting"; } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 5ebace2a4b..41b55b2d59 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -242,7 +243,7 @@ public class RegistryDirectory extends AbstractDirectory implements Notify // state change // If the calculation is wrong, it is not processed. - if (newUrlInvokerMap == null || newUrlInvokerMap.size() == 0) { + if (CollectionUtils.isEmptyMap(newUrlInvokerMap)) { logger.error(new IllegalStateException("urls to invokers error .invokerUrls.size :" + invokerUrls.size() + ", invoker.size :0. urls :" + invokerUrls .toString())); return; @@ -442,7 +443,7 @@ public class RegistryDirectory extends AbstractDirectory implements Notify } private URL overrideWithConfigurators(List configurators, URL url) { - if (configurators != null && !configurators.isEmpty()) { + if (CollectionUtils.isNotEmpty(configurators)) { for (Configurator configurator : configurators) { url = configurator.configure(url); } @@ -626,7 +627,7 @@ public class RegistryDirectory extends AbstractDirectory implements Notify } private void doOverrideUrl(List configurators) { - if (configurators != null && !configurators.isEmpty()) { + if (CollectionUtils.isNotEmpty(configurators)) { for (Configurator configurator : configurators) { this.overrideDirectoryUrl = configurator.configure(overrideDirectoryUrl); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index af908127e7..453f958541 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; @@ -120,7 +121,7 @@ public class RegistryProtocol implements Protocol { //Filter the parameters that do not need to be output in url(Starting with .) private static String[] getFilteredKeys(URL url) { Map params = url.getParameters(); - if (params != null && !params.isEmpty()) { + if (CollectionUtils.isNotEmptyMap(params)) { return params.keySet().stream() .filter(k -> k.startsWith(HIDE_KEY_PREFIX)) .toArray(String[]::new); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index 50c7bb10a2..4ea6108582 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -248,7 +249,7 @@ public abstract class AbstractRegistry implements Registry { NotifyListener listener = reference::set; subscribe(url, listener); // Subscribe logic guarantees the first notify to return List urls = reference.get(); - if (urls != null && !urls.isEmpty()) { + if (CollectionUtils.isNotEmpty(urls)) { for (URL u : urls) { if (!Constants.EMPTY_PROTOCOL.equals(u.getProtocol())) { result.add(u); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java index c7a4bb9bcb..cbf1527231 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java @@ -19,6 +19,7 @@ package org.apache.dubbo.registry.support; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.timer.HashedWheelTimer; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.retry.FailedNotifiedTask; @@ -291,7 +292,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { Throwable t = e; List urls = getCacheUrls(url); - if (urls != null && !urls.isEmpty()) { + if (CollectionUtils.isNotEmpty(urls)) { notify(url, listener, urls); logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t); } else { diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java index 06835dac6e..2a6e0817ae 100644 --- a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java +++ b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java @@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.ExecutorUtil; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.FailbackRegistry; @@ -204,7 +205,7 @@ public class MulticastRegistry extends FailbackRegistry { } else if (msg.startsWith(Constants.SUBSCRIBE)) { URL url = URL.valueOf(msg.substring(Constants.SUBSCRIBE.length()).trim()); Set urls = getRegistered(); - if (urls != null && !urls.isEmpty()) { + if (CollectionUtils.isNotEmpty(urls)) { for (URL u : urls) { if (UrlUtils.isMatch(url, u)) { String host = remoteAddress != null && remoteAddress.getAddress() != null @@ -363,7 +364,7 @@ public class MulticastRegistry extends FailbackRegistry { private List toList(Set urls) { List list = new ArrayList(); - if (urls != null && !urls.isEmpty()) { + if (CollectionUtils.isNotEmpty(urls)) { for (URL url : urls) { list.add(url); } @@ -406,7 +407,7 @@ public class MulticastRegistry extends FailbackRegistry { } if (urls.isEmpty()) { List cacheUrls = getCacheUrls(url); - if (cacheUrls != null && !cacheUrls.isEmpty()) { + if (CollectionUtils.isNotEmpty(cacheUrls)) { urls.addAll(cacheUrls); } } diff --git a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java index c0c7c22ff2..589e92f403 100644 --- a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java +++ b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java @@ -24,6 +24,8 @@ import org.apache.dubbo.common.utils.ExecutorUtil; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.UrlUtils; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.FailbackRegistry; import org.apache.dubbo.rpc.RpcException; @@ -53,7 +55,6 @@ import java.util.concurrent.atomic.AtomicInteger; /** * RedisRegistry - * */ public class RedisRegistry extends FailbackRegistry { @@ -124,7 +125,7 @@ public class RedisRegistry extends FailbackRegistry { List addresses = new ArrayList(); addresses.add(url.getAddress()); String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]); - if (backups != null && backups.length > 0) { + if (ArrayUtils.isNotEmpty(backups)) { addresses.addAll(Arrays.asList(backups)); } @@ -199,10 +200,10 @@ public class RedisRegistry extends FailbackRegistry { // The monitoring center is responsible for deleting outdated dirty data private void clean(Jedis jedis) { Set keys = jedis.keys(root + Constants.ANY_VALUE); - if (keys != null && !keys.isEmpty()) { + if (CollectionUtils.isNotEmpty(keys)) { for (String key : keys) { Map values = jedis.hgetAll(key); - if (values != null && values.size() > 0) { + if (CollectionUtils.isNotEmptyMap(values)) { boolean delete = false; long now = System.currentTimeMillis(); for (Map.Entry entry : values.entrySet()) { @@ -359,7 +360,7 @@ public class RedisRegistry extends FailbackRegistry { if (service.endsWith(Constants.ANY_VALUE)) { admin = true; Set keys = jedis.keys(service); - if (keys != null && !keys.isEmpty()) { + if (CollectionUtils.isNotEmpty(keys)) { Map> serviceKeys = new HashMap<>(); for (String key : keys) { String serviceKey = toServicePath(key); @@ -427,7 +428,7 @@ public class RedisRegistry extends FailbackRegistry { } List urls = new ArrayList<>(); Map values = jedis.hgetAll(key); - if (values != null && values.size() > 0) { + if (CollectionUtils.isEmptyMap(values)) { for (Map.Entry entry : values.entrySet()) { URL u = URL.valueOf(entry.getKey()); if (!u.getParameter(Constants.DYNAMIC_KEY, true) @@ -591,7 +592,7 @@ public class RedisRegistry extends FailbackRegistry { if (!first) { first = false; Set keys = jedis.keys(service); - if (keys != null && !keys.isEmpty()) { + if (CollectionUtils.isNotEmpty(keys)) { for (String s : keys) { doNotify(jedis, s); } diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 37f1f21a16..3ead544a64 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; @@ -149,7 +150,7 @@ public class ZookeeperRegistry extends FailbackRegistry { } zkClient.create(root, false); List services = zkClient.addChildListener(root, zkListener); - if (services != null && !services.isEmpty()) { + if (CollectionUtils.isNotEmpty(services)) { for (String service : services) { service = URL.decode(service); anyServices.add(service); @@ -264,7 +265,7 @@ public class ZookeeperRegistry extends FailbackRegistry { private List toUrlsWithoutEmpty(URL consumer, List providers) { List urls = new ArrayList<>(); - if (providers != null && !providers.isEmpty()) { + if (CollectionUtils.isNotEmpty(providers)) { for (String provider : providers) { provider = URL.decode(provider); if (provider.contains(Constants.PROTOCOL_SEPARATOR)) { diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeServer.java index 7f3067d60c..e339c15ab9 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeServer.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.Version; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.timer.HashedWheelTimer; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; @@ -155,7 +156,7 @@ public class HeaderExchangeServer implements ExchangeServer { public Collection getExchangeChannels() { Collection exchangeChannels = new ArrayList(); Collection channels = server.getChannels(); - if (channels != null && !channels.isEmpty()) { + if (CollectionUtils.isNotEmpty(channels)) { for (Channel channel : channels) { exchangeChannels.add(HeaderExchangeChannel.getOrAddChannel(channel)); } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/codec/TelnetCodec.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/codec/TelnetCodec.java index 6871740437..ce481fc851 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/codec/TelnetCodec.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/codec/TelnetCodec.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.RemotingException; @@ -72,7 +73,7 @@ public class TelnetCodec extends TransportCodec { URL url = channel.getUrl(); if (url != null) { String parameter = url.getParameter(Constants.CHARSET_KEY); - if (parameter != null && parameter.length() > 0) { + if (StringUtils.isNotEmpty(parameter)) { try { return Charset.forName(parameter); } catch (Throwable t) { @@ -196,7 +197,7 @@ public class TelnetCodec extends TransportCodec { boolean down = endsWith(message, DOWN); if (up || down) { LinkedList history = (LinkedList) channel.getAttribute(HISTORY_LIST_KEY); - if (history == null || history.isEmpty()) { + if (CollectionUtils.isEmpty(history)) { return DecodeResult.NEED_MORE_INPUT; } Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY); @@ -263,7 +264,7 @@ public class TelnetCodec extends TransportCodec { LinkedList history = (LinkedList) channel.getAttribute(HISTORY_LIST_KEY); Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY); channel.removeAttribute(HISTORY_INDEX_KEY); - if (history != null && !history.isEmpty() && index != null && index >= 0 && index < history.size()) { + if (CollectionUtils.isNotEmpty(history) && index != null && index >= 0 && index < history.size()) { String value = history.get(index); if (value != null) { byte[] b1 = value.getBytes(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java index a5ceda82f8..f740b3d0bd 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java @@ -74,7 +74,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne if (buf.length() > 0) { buf.append("\r\n"); } - if (prompt != null && prompt.length() > 0 && !noprompt) { + if (StringUtils.isNotEmpty(prompt) && !noprompt) { buf.append(prompt); } return buf.toString(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/HelpTelnetHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/HelpTelnetHandler.java index 84325918f8..b22cd1ac66 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/HelpTelnetHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/HelpTelnetHandler.java @@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.telnet.support.command; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.telnet.support.Help; @@ -54,7 +55,7 @@ public class HelpTelnetHandler implements TelnetHandler { } else { List> table = new ArrayList>(); List handlers = extensionLoader.getActivateExtension(channel.getUrl(), "telnet"); - if (handlers != null && !handlers.isEmpty()) { + if (CollectionUtils.isNotEmpty(handlers)) { for (TelnetHandler handler : handlers) { Help help = handler.getClass().getAnnotation(Help.class); List row = new ArrayList(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java index 6f22da21da..69611f60a0 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.status.Status; import org.apache.dubbo.common.status.StatusChecker; import org.apache.dubbo.common.status.support.StatusUtils; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.telnet.support.Help; @@ -48,7 +49,7 @@ public class StatusTelnetHandler implements TelnetHandler { String[] header = new String[]{"resource", "status", "message"}; List> table = new ArrayList>(); Map statuses = new HashMap(); - if (checkers != null && !checkers.isEmpty()) { + if (CollectionUtils.isNotEmpty(checkers)) { for (StatusChecker checker : checkers) { String name = extensionLoader.getExtensionName(checker); Status stat; @@ -79,7 +80,7 @@ public class StatusTelnetHandler implements TelnetHandler { } String status = channel.getUrl().getParameter("status"); Map statuses = new HashMap(); - if (status != null && status.length() > 0) { + if (CollectionUtils.isNotEmptyMap(statuses)) { String[] ss = Constants.COMMA_SPLIT_PATTERN.split(status); for (String s : ss) { StatusChecker handler = extensionLoader.getExtension(s); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java index ed913d2a0f..9b1c9ba8da 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java @@ -26,6 +26,7 @@ import org.apache.dubbo.common.store.DataStore; import org.apache.dubbo.common.utils.ExecutorUtil; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; import org.apache.dubbo.remoting.Client; @@ -124,7 +125,7 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client private static int getReconnectParam(URL url) { int reconnect; String param = url.getParameter(Constants.RECONNECT_KEY); - if (param == null || param.length() == 0 || "true".equalsIgnoreCase(param)) { + if (StringUtils.isEmpty(param) || "true".equalsIgnoreCase(param)) { reconnect = Constants.DEFAULT_RECONNECT_PERIOD; } else if ("false".equalsIgnoreCase(param)) { reconnect = 0; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java index cec8006882..783741b78e 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java @@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.transport; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.ChannelHandler; @@ -42,7 +43,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler { } public ChannelHandlerDispatcher(Collection handlers) { - if (handlers != null && !handlers.isEmpty()) { + if (CollectionUtils.isNotEmpty(handlers)) { this.channelHandlers.addAll(handlers); } } diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java index b0a1052409..49d3a02ce4 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java @@ -81,7 +81,7 @@ public class DeprecatedTelnetCodec implements Codec { URL url = channel.getUrl(); if (url != null) { String parameter = url.getParameter(Constants.CHARSET_KEY); - if (parameter != null && parameter.length() > 0) { + if (StringUtils.isNotEmpty(parameter)) { try { return Charset.forName(parameter); } catch (Throwable t) { diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java index f2ca73c347..61cd3f1ef0 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ExecutorUtil; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.NetUtils; @@ -106,7 +107,7 @@ public class NettyServer extends AbstractServer implements Server { } try { Collection channels = getChannels(); - if (channels != null && !channels.isEmpty()) { + if (CollectionUtils.isNotEmpty(channels)) { for (org.apache.dubbo.remoting.Channel channel : channels) { try { channel.close(); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/FormattingTuple.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/FormattingTuple.java index 49bbce1f7a..eac0a47494 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/FormattingTuple.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/FormattingTuple.java @@ -17,6 +17,8 @@ package org.apache.dubbo.remoting.transport.netty4.logging; +import org.apache.dubbo.common.utils.ArrayUtils; + /** * Holds the results of formatting done by {@link MessageFormatter}. */ @@ -43,7 +45,7 @@ class FormattingTuple { } static Object[] trimmedCopy(Object[] argArray) { - if (argArray == null || argArray.length == 0) { + if (ArrayUtils.isEmpty(argArray)) { throw new IllegalStateException("non-sensical empty or null argument array"); } final int trimmedLen = argArray.length - 1; diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java index 9bc3ff9989..c7cde8b3e0 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java @@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.transport.netty4.logging; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import java.text.MessageFormat; import java.util.HashMap; @@ -141,7 +142,7 @@ final class MessageFormatter { } static Throwable getThrowableCandidate(Object[] argArray) { - if (argArray == null || argArray.length == 0) { + if (ArrayUtils.isEmpty(argArray)) { return null; } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java index eaa467daa6..f6c5699fd0 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java @@ -19,6 +19,7 @@ package org.apache.dubbo.rpc; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThreadLocal; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -605,7 +606,7 @@ public class RpcContext { public RpcContext setInvokers(List> invokers) { this.invokers = invokers; - if (invokers != null && !invokers.isEmpty()) { + if (CollectionUtils.isNotEmpty(invokers)) { List urls = new ArrayList(invokers.size()); for (Invoker invoker : invokers) { urls.add(invoker.getUrl()); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 89eb070603..2690dbf11b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; @@ -140,7 +141,7 @@ public class AccessLogFilter implements Filter { } sn.append(") "); Object[] args = inv.getArguments(); - if (args != null && args.length > 0) { + if (ArrayUtils.isNotEmpty(args)) { sn.append(JSON.toJSONString(args)); } String msg = sn.toString(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerExporterWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerExporterWrapper.java index ca7fd93aae..7ac188e21d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerExporterWrapper.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerExporterWrapper.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.listener; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Invoker; @@ -41,7 +42,7 @@ public class ListenerExporterWrapper implements Exporter { } this.exporter = exporter; this.listeners = listeners; - if (listeners != null && !listeners.isEmpty()) { + if (CollectionUtils.isNotEmpty(listeners)) { RuntimeException exception = null; for (ExporterListener listener : listeners) { if (listener != null) { @@ -69,7 +70,7 @@ public class ListenerExporterWrapper implements Exporter { try { exporter.unexport(); } finally { - if (listeners != null && !listeners.isEmpty()) { + if (CollectionUtils.isNotEmpty(listeners)) { RuntimeException exception = null; for (ExporterListener listener : listeners) { if (listener != null) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java index f3e8f8054f..4c5498a383 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java @@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.listener; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.InvokerListener; @@ -44,7 +45,7 @@ public class ListenerInvokerWrapper implements Invoker { } this.invoker = invoker; this.listeners = listeners; - if (listeners != null && !listeners.isEmpty()) { + if (CollectionUtils.isNotEmpty(listeners)) { for (InvokerListener listener : listeners) { if (listener != null) { try { @@ -87,7 +88,7 @@ public class ListenerInvokerWrapper implements Invoker { try { invoker.destroy(); } finally { - if (listeners != null && !listeners.isEmpty()) { + if (CollectionUtils.isNotEmpty(listeners)) { for (InvokerListener listener : listeners) { if (listener != null) { try { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java index fd0cca6d8e..4979916e66 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; @@ -75,7 +76,7 @@ public abstract class AbstractInvoker implements Invoker { } private static Map convertAttachment(URL url, String[] keys) { - if (keys == null || keys.length == 0) { + if (ArrayUtils.isEmpty(keys)) { return null; } Map attachment = new HashMap(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java index ef9dac3b89..2e93259b76 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java @@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.PojoUtils; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.ProxyFactory; @@ -78,7 +79,7 @@ final public class MockInvoker implements Invoker { } else { value = mock; } - if (returnTypes != null && returnTypes.length > 0) { + if (ArrayUtils.isNotEmpty(returnTypes)) { value = PojoUtils.realize(value, (Class) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null); } return value; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java index 5242cbd893..ce5da6b51b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.support; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; public class ProtocolUtils { @@ -31,7 +32,7 @@ public class ProtocolUtils { public static String serviceKey(int port, String serviceName, String serviceVersion, String serviceGroup) { StringBuilder buf = new StringBuilder(); - if (serviceGroup != null && serviceGroup.length() > 0) { + if (StringUtils.isNotEmpty(serviceGroup)) { buf.append(serviceGroup); buf.append("/"); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java index e5a389950c..a5ae76133c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.RpcInvocation; @@ -47,7 +48,7 @@ public class RpcUtils { && invocation.getInvoker().getUrl() != null && !invocation.getMethodName().startsWith("$")) { String service = invocation.getInvoker().getUrl().getServiceInterface(); - if (service != null && service.length() > 0) { + if (StringUtils.isNotEmpty(service)) { Class invokerInterface = invocation.getInvoker().getInterface(); Class cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); @@ -71,7 +72,7 @@ public class RpcUtils { && invocation.getInvoker().getUrl() != null && !invocation.getMethodName().startsWith("$")) { String service = invocation.getInvoker().getUrl().getServiceInterface(); - if (service != null && service.length() > 0) { + if (StringUtils.isNotEmpty(service)) { Class invokerInterface = invocation.getInvoker().getInterface(); Class cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java index 53ae2bd457..d8406e861a 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.rpc.Filter; @@ -85,7 +86,7 @@ public class TraceFilter implements Filter { key = invoker.getInterface().getName(); channels = tracers.get(key); } - if (channels != null && !channels.isEmpty()) { + if (CollectionUtils.isNotEmpty(channels)) { for (Channel channel : new ArrayList(channels)) { if (channel.isConnected()) { try { diff --git a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java index ba4bb4f243..2d837ba5ed 100644 --- a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java +++ b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.protocol.http; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.http.HttpBinder; import org.apache.dubbo.remoting.http.HttpHandler; import org.apache.dubbo.remoting.http.HttpServer; @@ -132,7 +133,7 @@ public class HttpProtocol extends AbstractProxyProtocol { httpProxyFactoryBean.setServiceUrl(key); httpProxyFactoryBean.setServiceInterface(serviceType); String client = url.getParameter(Constants.CLIENT_KEY); - if (client == null || client.length() == 0 || "simple".equals(client)) { + if (StringUtils.isEmpty(client) || "simple".equals(client)) { SimpleHttpInvokerRequestExecutor httpInvokerRequestExecutor = new SimpleHttpInvokerRequestExecutor() { @Override protected void prepareConnection(HttpURLConnection con, diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java index 290e208430..e6959d4bd1 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java @@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.protocol.injvm; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; @@ -56,7 +57,7 @@ public class InjvmProtocol extends AbstractProtocol implements Protocol { if (!key.getServiceKey().contains("*")) { result = map.get(key.getServiceKey()); } else { - if (map != null && !map.isEmpty()) { + if (CollectionUtils.isNotEmptyMap(map)) { for (Exporter exporter : map.values()) { if (UrlUtils.isServiceKeyMatch(key, exporter.getInvoker().getUrl())) { result = exporter;