Repository navigation
[type: bug] Fix NPE in Hystrix/Resilience4J/Sentinel/RateLimiter plugins (#6877) - #7008
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Review: Fix NPE in Hystrix/Resilience4J/Sentinel/RateLimiter plugins (#6877)
Verdict: REQUEST CHANGES
What's correct
The null-guard logic for all four plugins is sound: when the cached handle is null, fall through to chain.execute(exchange) instead of dereferencing the handle and throwing an NPE. The Hystrix variant additionally logs the offending rule, which is helpful.
Compile-blocking defect: RateLimiterPlugin is missing the Objects import
RateLimiterPlugin.doExecute now uses Objects.isNull(limiterHandle):
RateLimiterHandle limiterHandle = RateLimiterPluginDataHandler.CACHED_HANDLE.get()
.obtainHandle(CacheKeyUtils.INST.getKey(rule));
if (Objects.isNull(limiterHandle)) { // <-- compile error
return chain.execute(exchange);
}but the file's imports are only:
import java.util.Optional;
import java.util.function.Consumer;There is no import java.util.Objects;. This will fail to compile (unresolved symbol Objects). The other three plugins are fine because they already import java.util.Objects (Objects.requireNonNull(shenyuContext) was already present in HystrixPlugin, Resilience4JPlugin, and SentinelPlugin), and HystrixPlugin already declares private static final Logger LOG. So only RateLimiterPlugin needs the fix.
Required change
Add the import at the top of RateLimiterPlugin.java:
import java.util.Objects;After that one-line addition the PR compiles and all four guards are correct.
Conclusion
The fix is the right idea and 3 of the 4 files are ready; please add the missing import java.util.Objects; to RateLimiterPlugin (and run a full mvn compile to confirm). Requesting changes until the import is added.
…ins (apache#6877) Signed-off-by: zhang-arvin <[email protected]>
a0675b4 to
5169568
Compare
|
Thanks for the review @Aias00! Fixed:
Please take another look. |
Aias00
left a comment
There was a problem hiding this comment.
Re-review: [type: bug] Fix NPE in Hystrix/Resilience4J/Sentinel/RateLimiter plugins (#6877)
Re-reviewed at head 5169568. My previous REQUEST_CHANGES flagged that RateLimiterPlugin calls Objects.isNull(...) but was missing import java.util.Objects;, so the module would not compile. That is now fixed:
RateLimiterPlugin.javaline 24 addsimport java.util.Objects;(verified: exactly one occurrence, no duplicate import). Theif (Objects.isNull(limiterHandle)) { return chain.execute(exchange); }guard now compiles and short-circuits the plugin safely when no handle is cached.HystrixPlugin(lines 9-12),Resilience4JPlugin(lines 46-48),SentinelPlugin(lines 60-62) each gain the same null-handle guard;HystrixPluginadditionally logs viaLOG, which is confirmed present (slf4jLogger/LoggerFactoryimports +LOGfield at lines 37-38/53).
Behavior is correct: a missing cached handle now falls through to chain.execute instead of throwing NPE on hystrixHandle.getGroupKey() / resilience4JHandle.checkData() / sentinelHandle.checkData().
The same fault-tolerance NPE fixes are also carried by #7022 (which subsumes this PR). Functionally this PR is correct and compiles; consider closing it as a duplicate once #7022 lands to avoid redundant merges, but it is safe to approve independently.
Approving.
…ins (apache#6877) (apache#7008) Signed-off-by: zhang-arvin <[email protected]> Co-authored-by: aias00 <[email protected]>
Closes #6877