diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/core/ServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/naming/core/ServerListManager.java index f130466189f..0cab2bd3414 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/core/ServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/core/ServerListManager.java @@ -86,11 +86,10 @@ public ServerListManager(Properties properties) { public ServerListManager(NacosClientProperties properties, String namespace) { this.namespace = namespace; initServerAddr(properties); - if (!serverList.isEmpty()) { - currentIndex.set(new Random().nextInt(serverList.size())); - } - if (serverList.isEmpty() && StringUtils.isEmpty(endpoint)) { + if (getServerList().isEmpty() && StringUtils.isEmpty(endpoint)) { throw new NacosLoadException("serverList is empty,please check configuration"); + } else { + currentIndex.set(new Random().nextInt(getServerList().size())); } }