Aias00 opened a new issue, #7452:
URL: https://github.com/apache/shenyu/issues/7452
## Is there an existing issue for this?
- [x] I searched open and closed issues.
## Current Behavior
A matched Cache rule with a null handle can enter the gateway rule cache,
then turn a successful downstream response into a `NullPointerException` when
the response body is written.
`CachePluginDataHandler.handlerRule()` skips a null `ruleData.handle`.
`CachePlugin.buildRuleHandle()` then returns null from the rule-handle cache,
but `CacheHttpResponse.cacheResponse()` unconditionally calls
`cacheRuleHandle.getTimeoutSeconds()`.
## Expected Behavior
A rule accepted by the configuration/sync path should not crash successful
responses. Either initialize documented default Cache settings or explicitly
skip caching when no usable handle exists. If a handle is mandatory, reject
that configuration consistently before publishing it.
## Steps To Reproduce
1. Enable the Cache plugin using the memory backend.
2. Synchronize an enabled selector and a matching Cache rule with
`handle=null` through the real `CommonPluginDataSubscriber`.
3. Execute `CachePlugin.execute()` with a downstream chain that writes a
plain-text response body.
4. Observe an NPE at `CachePlugin.java:146`.
An offline harness executed the actual subscriber, handler, matching plugin
and decorated response. The same setup with `handle={"timeoutSeconds":60}`
completed successfully:
```text
cachedHandle[valid]=CacheRuleHandle
validHandle=completed
cachedHandle[null]=null
nullHandle=java.lang.NullPointerException: Cannot invoke
CacheRuleHandle.getTimeoutSeconds() because this.cacheRuleHandle is null
```
## Reachability And Location
-
[RuleDTO.java:86](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/RuleDTO.java#L86):
the handle field has no non-null validation constraint.
-
[RuleServiceImpl.java:418](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java#L418):
special handle validation applies only to agentGateway, not Cache.
-
[CommonPluginDataSubscriber.java:253](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java#L253):
accepts the rule into the gateway cache.
-
[CachePluginDataHandler.java:113](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-handler/src/main/java/org/apache/shenyu/plugin/cache/handler/CachePluginDataHandler.java#L113):
null handles do not populate the specific handle cache.
-
[CachePlugin.java:107](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-handler/src/main/java/org/apache/shenyu/plugin/cache/CachePlugin.java#L107):
lookup has no default.
-
[CachePlugin.java:146](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-handler/src/main/java/org/apache/shenyu/plugin/cache/CachePlugin.java#L146):
null dereference during response caching.
## Impact
Severity: Medium. Confidence: high. Coverage: confirmed by an actual offline
plugin execution.
Requests matching an accepted Cache rule without a handle fail during
response processing instead of returning the otherwise successful downstream
body. This requires absent/uncached rule settings; normal populated settings
are the successful control case.
## Suggested Fix And Regression Tests
Choose an explicit missing-handle policy: supply
`CacheRuleHandle.newInstance()` defaults, skip caching, or reject invalid Cache
rules at the configuration boundary. Verify missing, default and explicit
timeout handles through real rule subscription plus `CachePlugin.execute()` and
response writing.
## Validation And Related Issues
Reviewed `master` at `67596c1d228b62da75cd0a0ecb47d0ac5d995384`
(`2.7.2-SNAPSHOT`). Independent review and leader reproduction both confirmed
the crash. Existing `CachePluginTest`: 5 tests passed, but lack this case.
#6877 covered similar absent-handle failures in
Hystrix/Resilience4J/Sentinel/RateLimiter. #6772 covered stale handle removal
in other handlers. #6505/#6506 cover Cache response restoration/key semantics.
This report is the current Cache response-write null-handle path.
No live Admin/dashboard/gateway E2E environment was started. The
DTO/service/schema acceptance path was inspected; the offline runtime harness
starts at the gateway subscriber.
--
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]