From f17f40e0af70f5519765af347811b21eb06456d1 Mon Sep 17 00:00:00 2001 From: slievrly Date: Tue, 25 Jun 2019 21:42:13 +0800 Subject: [PATCH] fix review Signed-off-by: slievrly --- .../filter/impl/ConfigFilterChainManager.java | 4 +-- .../client/config/impl/ServerListManager.java | 29 +++++++++++------ .../nacos/client/config/utils/ParamUtils.java | 4 +-- .../server/service/ServerListService.java | 31 +++++++++++-------- .../nacos/config/server/utils/ParamUtils.java | 11 +++---- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/config/filter/impl/ConfigFilterChainManager.java b/client/src/main/java/com/alibaba/nacos/client/config/filter/impl/ConfigFilterChainManager.java index 8650a0d73..be55bacc3 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/filter/impl/ConfigFilterChainManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/filter/impl/ConfigFilterChainManager.java @@ -22,6 +22,7 @@ import com.alibaba.nacos.api.config.filter.IConfigFilterChain; import com.alibaba.nacos.api.config.filter.IConfigRequest; import com.alibaba.nacos.api.config.filter.IConfigResponse; import com.alibaba.nacos.api.exception.NacosException; + import com.google.common.collect.Lists; /** @@ -72,8 +73,7 @@ public class ConfigFilterChainManager implements IConfigFilterChain { @Override public void doFilter(final IConfigRequest request, final IConfigResponse response) throws NacosException { - if (this.currentPosition == this.additionalFilters.size()) { - } else { + if (this.currentPosition != this.additionalFilters.size()) { this.currentPosition++; IConfigFilter nextFilter = this.additionalFilters.get(this.currentPosition - 1); nextFilter.doFilter(request, response, this); diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java index f28c00dde..85bd6282d 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java @@ -15,21 +15,31 @@ */ package com.alibaba.nacos.client.config.impl; +import java.io.IOException; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.SystemPropertyKeyConst; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; import com.alibaba.nacos.client.config.utils.IOUtils; -import com.alibaba.nacos.client.utils.*; -import org.slf4j.Logger; +import com.alibaba.nacos.client.utils.EnvUtil; +import com.alibaba.nacos.client.utils.LogUtils; +import com.alibaba.nacos.client.utils.ParamUtil; +import com.alibaba.nacos.client.utils.StringUtils; +import com.alibaba.nacos.client.utils.TemplateUtils; -import java.io.IOException; -import java.io.StringReader; -import java.net.HttpURLConnection; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; /** * Serverlist Manager @@ -284,8 +294,7 @@ public class ServerListManager { List lines = IOUtils.readLines(new StringReader(httpResult.content)); List result = new ArrayList(lines.size()); for (String serverAddr : lines) { - if (null == serverAddr || serverAddr.trim().isEmpty()) { - } else { + if (org.apache.commons.lang3.StringUtils.isNotBlank(serverAddr)) { String[] ipPort = serverAddr.trim().split(":"); String ip = ipPort[0].trim(); if (ipPort.length == 1) { diff --git a/client/src/main/java/com/alibaba/nacos/client/config/utils/ParamUtils.java b/client/src/main/java/com/alibaba/nacos/client/config/utils/ParamUtils.java index 55defb6d2..477db7e27 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/utils/ParamUtils.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/utils/ParamUtils.java @@ -43,9 +43,7 @@ public class ParamUtils { int length = param.length(); for (int i = 0; i < length; i++) { char ch = param.charAt(i); - if (Character.isLetterOrDigit(ch)) { - } else if (isValidChar(ch)) { - } else { + if (!Character.isLetterOrDigit(ch) && !isValidChar(ch)) { return false; } } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/ServerListService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/ServerListService.java index cb60eebe1..0a6f36c1d 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/ServerListService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/ServerListService.java @@ -15,6 +15,20 @@ */ package com.alibaba.nacos.config.server.service; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import javax.annotation.PostConstruct; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletResponse; + import com.alibaba.nacos.config.server.constant.Constants; import com.alibaba.nacos.config.server.monitor.MetricsMonitor; import com.alibaba.nacos.config.server.service.notify.NotifyService; @@ -23,6 +37,7 @@ import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.config.server.utils.PropertyUtil; import com.alibaba.nacos.config.server.utils.RunningConfigUtils; import com.alibaba.nacos.config.server.utils.event.EventDispatcher; + import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; @@ -39,20 +54,11 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; -import javax.annotation.PostConstruct; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.StringReader; -import java.util.*; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - +import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog; +import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP; import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE; import static com.alibaba.nacos.core.utils.SystemUtils.readClusterConf; -import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog; -import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; /** * Serverlist service @@ -261,8 +267,7 @@ public class ServerListService implements ApplicationListener lines = IOUtils.readLines(new StringReader(result.content)); List ips = new ArrayList(lines.size()); for (String serverAddr : lines) { - if (null == serverAddr || serverAddr.trim().isEmpty()) { - } else { + if (StringUtils.isNotBlank(serverAddr)) { ips.add(getFormatServerAddr(serverAddr)); } } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java b/config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java index 413ef404b..793810ed7 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java @@ -15,11 +15,12 @@ */ package com.alibaba.nacos.config.server.utils; -import com.alibaba.nacos.config.server.exception.NacosException; -import org.apache.commons.lang3.StringUtils; - import java.util.Map; +import com.alibaba.nacos.config.server.exception.NacosException; + +import org.apache.commons.lang3.StringUtils; + /** * 参数合法性检查工具类 * @@ -46,9 +47,7 @@ public class ParamUtils { int length = param.length(); for (int i = 0; i < length; i++) { char ch = param.charAt(i); - if (Character.isLetterOrDigit(ch)) { - } else if (isValidChar(ch)) { - } else { + if (!Character.isLetterOrDigit(ch) && !isValidChar(ch)) { return false; } }