Skip to content

[type: bug] Fix NPE in Hystrix/Resilience4J/Sentinel/RateLimiter plugins (#6877) - #7008

Merged
Aias00 merged 2 commits into
apache:masterfrom
zhang-arvin:fix/6877-plugin-npe
Sep 4, 2026
Merged

Aias00 merged 2 commits into
apache:masterfrom
zhang-arvin:fix/6877-plugin-npe

Conversation

@zhang-arvin

Copy link
Copy Markdown
Contributor

Closes #6877

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zhang-arvin

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Aias00! Fixed:

  • Added missing import java.util.Objects; in RateLimiterPlugin.java

Please take another look.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.java line 24 adds import java.util.Objects; (verified: exactly one occurrence, no duplicate import). The if (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; HystrixPlugin additionally logs via LOG, which is confirmed present (slf4j Logger/LoggerFactory imports + LOG field 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.

@Aias00
Aias00 merged commit d3dcaa8 into apache:master Sep 4, 2026
40 checks passed
eye-gu pushed a commit to eye-gu/shenyu that referenced this pull request Sep 30, 2026
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hystrix / Resilience4J / Sentinel / RateLimiter plugins NPE when a matched rule has no cached handle

2 participants