{"record":{"id":"9a3199645b649f90","repo":"yudaocode/SpringBoot-Labs","slug":"id-9a3199","errorCode":null,"errorMessage":"id 参数不允许为空","messagePattern":"id 参数不允许为空","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":200,"severity":"info","filePath":"labx-04-spring-cloud-alibaba-sentinel/labx-04-sca-sentinel-file-provider/src/main/java/cn/iocoder/springcloudalibaba/labx04/sentineldemo/provider/controller/DemoController.java","lineNumber":69,"sourceCode":"            return \"执行成功\";\n        } catch (BlockException ex) { // <3>\n            return \"被拒绝\";\n        } finally {\n            // <4> 释放资源\n            if (entry != null) {\n                entry.exit();\n            }\n        }\n    }\n\n    // 测试「Sentinel @SentinelResource 注解」\n    @GetMapping(\"/annotations_demo\")\n    @SentinelResource(value = \"annotations_demo_resource\",\n            blockHandler = \"blockHandler\",\n            fallback = \"fallback\")\n    public String annotationsDemo(@RequestParam(required = false) Integer id) throws InterruptedException {\n        if (id == null) {\n            throw new IllegalArgumentException(\"id 参数不允许为空\");\n        }\n        return \"success...\";\n    }\n\n    // BlockHandler 处理函数，参数最后多一个 BlockException，其余与原函数一致.\n    public String blockHandler(Integer id, BlockException ex) {\n        return \"block：\" + ex.getClass().getSimpleName();\n    }\n\n    // Fallback 处理函数，函数签名与原函数一致或加一个 Throwable 类型的参数.\n    public String fallback(Integer id, Throwable throwable) {\n        return \"fallback：\" + throwable.getMessage();\n    }\n\n}\n","sourceCodeStart":51,"sourceCodeEnd":85,"githubUrl":"https://github.com/yudaocode/SpringBoot-Labs/blob/6c12efaed06d12907a0f40dd2ad1f7020aec8798/labx-04-spring-cloud-alibaba-sentinel/labx-04-sca-sentinel-file-provider/src/main/java/cn/iocoder/springcloudalibaba/labx04/sentineldemo/provider/controller/DemoController.java#L51-L85","documentation":"Intentional validation exception in the Sentinel lab's file-storage variant. /annotations_demo (a @SentinelResource resource with blockHandler and fallback) throws IllegalArgumentException('id 参数不允许为空') when the optional id query parameter is omitted; the Sentinel annotation interceptor routes it to the fallback method, which returns 'fallback：id 参数不允许为空' over HTTP 200. The lab demonstrates fallback handling with rules persisted to a local file.","triggerScenarios":"GET /annotations_demo with no id parameter — the guard at line 69 throws and fallback echoes the message.","commonSituations":"Testing degrade/flow rules loaded from the sentinel-dashboard rules file and forgetting the id parameter; expecting an error status and getting the fallback body; mixing up which handler fires (fallback for exceptions, blockHandler for BlockException).","solutions":["Add ?id=1 to see 'success...'.","Use the fallback response as a sanity check that the annotation aspect and file-based rules are loaded.","Make id a required parameter to get standard 400 validation instead."],"exampleFix":"// before\npublic String annotationsDemo(@RequestParam(required = false) Integer id) {\n    if (id == null) { throw new IllegalArgumentException(\"id 参数不允许为空\"); }\n    return \"success...\";\n}\n\n// after\npublic String annotationsDemo(@RequestParam Integer id) {\n    return \"success...\";\n}","handlingStrategy":"try-catch","validationCode":"// Always call with an explicit id\n// curl 'http://localhost:8080/demo/annotations_demo?id=1'","typeGuard":null,"tryCatchPattern":"// Server already falls back; if wrapping without Sentinel:\ntry {\n    return controller.annotationsDemo(id);\n} catch (IllegalArgumentException e) {\n    return \"missing required parameter: id\";\n}","preventionTips":["Send the id parameter in every request.","Understand the lab's fallback/blockHandler split before testing rules.","Make params required when the value has no valid default."],"tags":["sentinel","file-rules","spring-cloud-alibaba","tutorial-demo","fallback","validation"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}