[BUG] Request plugin fails when rule handle contains only partial config sections
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues.
### Apache ShenYu Component
shenyu-plugin
### What happened
`RequestPlugin` calls `requestHandle.isEmptyConfig()` before applying request mutations:
```java
if (requestHandle.isEmptyConfig()) {
LOG.warn("request handler configuration is empty:{}", requestHandle);
return chain.execute(exchange);
}
```
`RequestHandle.isEmptyConfig()` delegates to `isNotEmptyConfig()`, which dereferences all three nested config sections without null checks:
```java
private boolean isNotEmptyConfig() {
return header.isNotEmptyConfig() || parameter.isNotEmptyConfig() || cookie.isNotEmptyConfig();
}
```
But `header`, `parameter`, and `cookie` are nullable fields. A valid partial request rule can configure only headers, only parameters, or only cookies. In those cases the first missing section causes a `NullPointerException` before the plugin applies the configured mutation.
Example handle that should be valid but fails because `parameter` and `cookie` are null:
```json
{
"header": {
"addHeaders": {"X-Test":"1"}
}
}
```
The plugin should apply the header change, but `RequestHandle.isNotEmptyConfig()` evaluates `parameter.isNotEmptyConfig()` after the header check if the first section is empty, or immediately fails when `header` itself is absent for parameter/cookie-only config.
### Expected behavior
The request plugin should treat missing nested sections as empty. `isNotEmptyConfig()` should check each section for null before calling its `isNotEmptyConfig()` method, so partial request mutation configurations work correctly.
### How to reproduce
1. Enable the request plugin.
2. Create a request plugin rule whose handle contains only one of `header`, `parameter`, or `cookie` sections.
3. Send a request matching the rule.
4. The request fails with `NullPointerException` from `RequestHandle.isNotEmptyConfig()` instead of applying the configured mutation.
### Debug logs
_No response_
### Environment
Current `master` branch.
### Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at RequestPlugin and follow its call to RequestHandle.isEmptyConfig(), then inspect isNotEmptyConfig() with header-only, parameter-only, and cookie-only handles. Verify that missing nested sections are treated as empty and that the configured request mutation is applied without a NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100