This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new df1389f3f0 fix shenyu-registry-nacos : modify nacos instance check. 
(#6178)
df1389f3f0 is described below

commit df1389f3f098066a9949620c18b127b6fc87af15
Author: Evan <[email protected]>
AuthorDate: Wed Sep 24 21:21:27 2025 +0800

    fix shenyu-registry-nacos : modify nacos instance check. (#6178)
    
    * fix : "com.alibaba.nacos.api.naming.po jo.Instance.getInstanceId()" is 
null
    
    issues: https://github.com/apache/shenyu/issues/6143
    
    * fix : code style
    
    ---------
    
    Co-authored-by: Evan <>
    Co-authored-by: aias00 <[email protected]>
---
 .../registry/nacos/NacosInstanceRegisterRepository.java     | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 
a/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
 
b/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
index 78405f843c..1044a06a9d 100644
--- 
a/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
+++ 
b/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
@@ -25,6 +25,8 @@ import com.alibaba.nacos.api.naming.listener.EventListener;
 import com.alibaba.nacos.api.naming.listener.NamingEvent;
 import com.alibaba.nacos.api.naming.pojo.Instance;
 import com.google.gson.JsonObject;
+
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.common.constant.Constants;
 import org.apache.shenyu.common.exception.ShenyuException;
 import org.apache.shenyu.common.utils.GsonUtils;
@@ -185,9 +187,14 @@ public class NacosInstanceRegisterRepository implements 
ShenyuInstanceRegisterRe
         }
 
         Set<Instance> updatedInstances = currentInstances.stream()
-                .filter(currentInstance -> previousInstances.stream()
-                        .anyMatch(previousInstance -> 
currentInstance.getInstanceId().equals(previousInstance.getInstanceId()) && 
!currentInstance.equals(previousInstance)))
-                .collect(Collectors.toSet());
+            .filter(
+                currentInstance -> 
Objects.nonNull(currentInstance.getInstanceId())
+                    && previousInstances.stream().anyMatch(
+                        previousInstance -> 
StringUtils.isNotBlank(previousInstance.getInstanceId())
+                        && 
currentInstance.getInstanceId().equals(previousInstance.getInstanceId())
+                        && !currentInstance.equals(previousInstance)))
+            .collect(Collectors.toSet());
+
         if (!updatedInstances.isEmpty()) {
             for (Instance instance: updatedInstances) {
                 listener.onEvent(instance.getServiceName(), 
buildUpstreamJsonFromInstance(instance), ChangedEventListener.Event.UPDATED);

Reply via email to