HY-love-sleep opened a new pull request, #7167:
URL: https://github.com/apache/shenyu/pull/7167

   ### Motivation
   
   Fixes #6657. `GeneralContextPlugin.doExecute` dereferenced the rule handle 
map without a null check:
   
   ```java
   Map<String, List<GeneralContextHandle>> generalContextHandleMap = 
GeneralContextPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
   if (generalContextHandleMap.isEmpty()) {
   ```
   
   `CommonHandleCache.obtainHandle` returns `null` on a miss, so a rule that 
reaches the plugin without a cached
   handle makes it throw a `NullPointerException` — the request fails instead 
of continuing through the chain.
   Every other plugin of this set guards its handle before using it 
(`ContextPathPlugin`, `RewritePlugin`, ...),
   this one was the exception.
   
   ### What changed
   
   ```java
   // the rule may have no cached handle, the cache returns null on a miss
   if (Objects.isNull(generalContextHandleMap) || 
generalContextHandleMap.isEmpty()) {
       return chain.execute(exchange);
   }
   ```
   
   A rule without a cached handle now passes through the chain untouched, 
exactly like a rule with an empty
   handle map does today.
   
   ### Testing
   
   ```
   ./mvnw -pl 
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-general-context
 -am test
   ```
   
   `BUILD SUCCESS`, checkstyle clean, `GeneralContextPluginTest` 4/4 including 
the new case: with no cached handle
   for the rule the request reaches the chain unchanged and no general context 
attribute is added to the exchange.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to