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 760516eab23..b306a85e059 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 @@ -223,7 +223,7 @@ public ServerListManager(Properties properties) throws NacosException { } private String initServerName(Properties properties) { - String serverName = ""; + String serverName; //1.user define server name. if (properties != null && properties.containsKey(PropertyKeyConst.SERVER_NAME)) { serverName = properties.get(PropertyKeyConst.SERVER_NAME).toString(); @@ -231,7 +231,7 @@ private String initServerName(Properties properties) { // if fix url,use fix url join string. if (isFixed) { serverName = FIXED_NAME + "-" + (StringUtils.isNotBlank(namespace) ? (StringUtils.trim(namespace) + "-") - : "") + getFixedNameSuffix(serverUrls.toArray(new String[serverUrls.size()])); + : "") + getFixedNameSuffix(serverUrls.toArray(new String[0])); } else { //if use endpoint , use endpoint ,content path ,serverlist name serverName = CUSTOM_NAME + "-" + String @@ -239,8 +239,8 @@ private String initServerName(Properties properties) { StringUtils.isNotBlank(namespace) ? ("_" + StringUtils.trim(namespace)) : ""); } } - serverName.replaceAll("\\/", "_"); - serverName.replaceAll("\\:", "_"); + serverName = serverName.replaceAll("\\/", "_"); + serverName = serverName.replaceAll("\\:", "_"); return serverName; }