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

Aias00 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 2811a622da fix(sofa): compare metadata fields null safely (#7112)
2811a622da is described below

commit 2811a622daefa2a588516eff4719a2c565475f7b
Author: Liming Deng <[email protected]>
AuthorDate: Tue Sep 22 20:12:47 2026 +0800

    fix(sofa): compare metadata fields null safely (#7112)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../plugin/sofa/handler/SofaMetaDataHandler.java   |  2 +-
 .../sofa/handler/SofaMetaDataHandlerTest.java      | 30 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
index a318780d19..754b2ee6b2 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
@@ -40,7 +40,7 @@ public class SofaMetaDataHandler implements MetaDataHandler {
             // The first initialization
             ApplicationConfigCache.getInstance().initRef(metaData);
         } else {
-            if (!exist.getServiceName().equals(metaData.getServiceName()) || 
!exist.getRpcExt().equals(metaData.getRpcExt())) {
+            if (!Objects.equals(exist.getServiceName(), 
metaData.getServiceName()) || !Objects.equals(exist.getRpcExt(), 
metaData.getRpcExt())) {
                 // remove old upstream reference
                 
ApplicationConfigCache.getInstance().invalidateWithMetadataPath(metaData.getPath());
                 // update
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
index 1699d3eeb9..2bf9e3271d 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
@@ -17,13 +17,24 @@
 
 package org.apache.shenyu.plugin.sofa.handler;
 
+import com.alipay.sofa.rpc.api.GenericService;
+import com.alipay.sofa.rpc.config.ConsumerConfig;
+import com.google.common.cache.LoadingCache;
+import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.shenyu.common.dto.MetaData;
 import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.plugin.sofa.cache.ApplicationConfigCache;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.lang.reflect.Field;
+import java.util.concurrent.ConcurrentMap;
+
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * SofaMetaDataHandlerTest.
@@ -53,4 +64,23 @@ public class SofaMetaDataHandlerTest {
         metaData.setServiceName("serviceName");
         assertDoesNotThrow(() -> sofaMetaDataHandler.handle(metaData));
     }
+
+    @Test
+    @SuppressWarnings("all")
+    public void handleNullMetadataFieldsTest() throws IllegalAccessException {
+        final String path = "null-metadata-fields";
+        final MetaData metaData = MetaData.builder().path(path).build();
+        final Field metadataField = 
FieldUtils.getDeclaredField(SofaMetaDataHandler.class, "META_DATA", true);
+        assertNotNull(metadataField);
+        ((ConcurrentMap) metadataField.get(null)).put(path, metaData);
+        ConsumerConfig consumerConfig = mock(ConsumerConfig.class);
+        when(consumerConfig.refer()).thenReturn(mock(GenericService.class));
+        final Field cacheField = 
FieldUtils.getDeclaredField(ApplicationConfigCache.class, "cache", true);
+        assertNotNull(cacheField);
+        ((LoadingCache) 
cacheField.get(ApplicationConfigCache.getInstance())).put(path, consumerConfig);
+
+        assertDoesNotThrow(() -> sofaMetaDataHandler.handle(metaData));
+
+        sofaMetaDataHandler.remove(metaData);
+    }
 }

Reply via email to