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 9b16d97f7b fix: guard the rule handle of the general context plugin 
(#6657) (#7167)
9b16d97f7b is described below

commit 9b16d97f7b2fedd466ccbf3a7db6829e75a82380
Author: HY-love-sleep <[email protected]>
AuthorDate: Wed Sep 23 10:30:50 2026 +0800

    fix: guard the rule handle of the general context plugin (#6657) (#7167)
---
 .../shenyu/plugin/general/context/GeneralContextPlugin.java |  4 +++-
 .../plugin/general/context/GeneralContextPluginTest.java    | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/main/java/org/apache/shenyu/plugin/general/context/GeneralContextPlugin.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/main/java/org/apache/shenyu/plugin/general/context/GeneralContextPlugin.java
index 8c270d131b..a10c6ade04 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/main/java/org/apache/shenyu/plugin/general/context/GeneralContextPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/main/java/org/apache/shenyu/plugin/general/context/GeneralContextPlugin.java
@@ -37,6 +37,7 @@ import reactor.core.publisher.Mono;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * GeneralContextPlugin, transfer http headers to rpc context.
@@ -51,7 +52,8 @@ public class GeneralContextPlugin extends 
AbstractShenyuPlugin {
     @Override
     protected Mono<Void> doExecute(final ServerWebExchange exchange, final 
ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
         Map<String, List<GeneralContextHandle>> generalContextHandleMap = 
GeneralContextPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
-        if (generalContextHandleMap.isEmpty()) {
+        // the rule may have no cached handle, the cache returns null on a miss
+        if (Objects.isNull(generalContextHandleMap) || 
generalContextHandleMap.isEmpty()) {
             return chain.execute(exchange);
         }
         Map<String, Map<String, String>> generalContextMap = new HashMap<>();
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/test/java/org/apache/shenyu/plugin/general/context/GeneralContextPluginTest.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/test/java/org/apache/shenyu/plugin/general/context/GeneralContextPluginTest.java
index 105348f8db..8c1b1ab2dd 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/test/java/org/apache/shenyu/plugin/general/context/GeneralContextPluginTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context/src/test/java/org/apache/shenyu/plugin/general/context/GeneralContextPluginTest.java
@@ -108,6 +108,19 @@ public class GeneralContextPluginTest {
         assertNull(shenyuGeneralContext);
     }
 
+    @Test
+    public void testDoExecuteWithoutACachedHandlePassesThrough() {
+        // regression for #6657: the rule handle cache returns null on a miss, 
the plugin must not dereference it
+        
GeneralContextPluginDataHandler.CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(this.ruleData));
+        when(this.chain.execute(any())).thenReturn(Mono.empty());
+
+        StepVerifier.create(generalContextPlugin.doExecute(this.exchange, 
this.chain, mock(SelectorData.class), this.ruleData))
+                .expectSubscription().verifyComplete();
+
+        Mockito.verify(this.chain, times(1)).execute(this.exchange);
+        
assertNull(this.exchange.getAttributes().get(Constants.GENERAL_CONTEXT));
+    }
+
     @Test
     public void testGetOrder() {
         assertEquals(this.generalContextPlugin.getOrder(), 
PluginEnum.GENERAL_CONTEXT.getCode());

Reply via email to