yudaocode/SpringBoot-Labs · info · java.lang.IllegalArgumentException
id 参数不允许为空
Error message
id 参数不允许为空
What it means
Intentional validation exception in the Sentinel lab (Apollo rule-storage variant). /annotations_demo declares @SentinelResource with blockHandler and fallback; omitting the optional id parameter makes the method throw IllegalArgumentException('id 参数不允许为空'), which Sentinel intercepts and passes to the configured fallback — the client sees 'fallback:id 参数不允许为空' with HTTP 200. Identical demo code across the lab's storage variants (Apollo/Nacos/file/actuator).
Source
Thrown at labx-04-spring-cloud-alibaba-sentinel/labx-04-sca-sentinel-apollo-provider/src/main/java/cn/iocoder/springcloudalibaba/labx04/sentineldemo/provider/controller/DemoController.java:69
return "执行成功";
} catch (BlockException ex) { // <3>
return "被拒绝";
} finally {
// <4> 释放资源
if (entry != null) {
entry.exit();
}
}
}
// 测试「Sentinel @SentinelResource 注解」
@GetMapping("/annotations_demo")
@SentinelResource(value = "annotations_demo_resource",
blockHandler = "blockHandler",
fallback = "fallback")
public String annotationsDemo(@RequestParam(required = false) Integer id) throws InterruptedException {
if (id == null) {
throw new IllegalArgumentException("id 参数不允许为空");
}
return "success...";
}
// BlockHandler 处理函数,参数最后多一个 BlockException,其余与原函数一致.
public String blockHandler(Integer id, BlockException ex) {
return "block:" + ex.getClass().getSimpleName();
}
// Fallback 处理函数,函数签名与原函数一致或加一个 Throwable 类型的参数.
public String fallback(Integer id, Throwable throwable) {
return "fallback:" + throwable.getMessage();
}
}
View on GitHub (pinned to 6c12efaed0)
Solutions
- Call /annotations_demo?id=1 for the success path.
- Treat the 'fallback:...' response as the demo demonstrating fallback — no server fix needed.
- If a hard 400 is wanted, make id a required @RequestParam.
Example fix
// before
public String annotationsDemo(@RequestParam(required = false) Integer id) {
if (id == null) { throw new IllegalArgumentException("id 参数不允许为空"); }
return "success...";
}
// after
public String annotationsDemo(@RequestParam Integer id) {
return "success...";
} Defensive patterns
Strategy: try-catch
Validate before calling
// GET /demo/annotations_demo?id=1 — parameter present, no exception
if (id == null) { /* supply id before calling */ } Try / catch
// Server side this is already handled by the Sentinel fallback; on your own client:
try {
String r = call("/annotations_demo", "id", "1");
} catch (IllegalArgumentException e) {
// defensive: shouldn't happen when id is supplied
} Prevention
- Include the id parameter in every request to this endpoint.
- Keep fallback signatures matching (same params + Throwable) so routing works.
- Don't treat the 200 'fallback:...' body as a server error.
When it happens
Trigger: GET /annotations_demo with no id parameter; the fallback method receives the IllegalArgumentException as its Throwable argument and echoes its message.
Common situations: Exploring how Apollo-persisted Sentinel rules behave and hitting the fallback earlier than expected; testing whether blockHandler vs fallback fires — flow-control (BlockException) goes to blockHandler, this IllegalArgumentException goes to fallback; forgetting the query parameter in manual curl tests.
Related errors
AI-assisted analysis of yudaocode/SpringBoot-Labs@6c12efaed0 (2026-08-14).
Data as JSON: /api/errors/cc7296dfbcd00e61.
Report an issue: GitHub.