{"record":{"id":"7dee5b319fe5ec82","repo":"yudaocode/SpringBoot-Labs","slug":"id-7dee5b","errorCode":null,"errorMessage":"id 参数不允许为空","messagePattern":"id 参数不允许为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"lab-46/lab-46-sentinel-demo-file/src/main/java/cn/iocoder/springboot/lab46/sentineldemo/controller/DemoController.java","lineNumber":67,"sourceCode":"            return \"执行成功\";\n        } catch (BlockException ex) {\n            return \"被拒绝\";\n        } finally {\n            // 释放资源\n            if (entry != null) {\n                entry.exit();\n            }\n        }\n    }\n\n    // 测试 @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":49,"sourceCodeEnd":83,"githubUrl":"https://github.com/yudaocode/SpringBoot-Labs/blob/6c12efaed06d12907a0f40dd2ad1f7020aec8798/lab-46/lab-46-sentinel-demo-file/src/main/java/cn/iocoder/springboot/lab46/sentineldemo/controller/DemoController.java#L49-L83","documentation":"Identical demo to error 8 but in lab-46-sentinel-demo-file, where Sentinel dashboard/rules are persisted via the file data source instead of Apollo. GET /demo/annotations_demo without id throws IllegalArgumentException, caught by the @SentinelResource fallback and returned as 'fallback: id 参数不允许为空'.","triggerScenarios":"GET /demo/annotations_demo with no id parameter on the file-based Sentinel lab; fallback method handles the thrown IllegalArgumentException.","commonSituations":"Same wiring pitfalls as error 8 (signature mismatch, missing fallbackClass). File-source specific: developers edit the rules JSON while the app runs and see stale behavior because the file source reloads only on change events (or needs a scheduled refresh), so fallback behavior may not match the file contents they just edited.","solutions":["Pass ?id=1 for the success path.","When fallback behavior seems stale, verify the file data source actually reloaded the rules (check Sentinel logs / dashboard connection) before blaming the fallback method.","Keep fallback/blockHandler signatures exactly aligned with the resource method.","Return a machine-readable degradation payload from fallback rather than a demo string for real services."],"exampleFix":"// before: String fallback string only useful for demos\npublic String fallback(Integer id, Throwable throwable) {\n    return \"fallback：\" + throwable.getMessage();\n}\n\n// after: structured degradation response\npublic CommonResult<String> fallback(Integer id, Throwable throwable) {\n    return CommonResult.error(DEGRADED, \"degraded: \" + throwable.getMessage());\n}","handlingStrategy":"validation","validationCode":"if (id == null) { // in the caller/test\n    throw new IllegalArgumentException(\"missing id\"); // or just send ?id=1\n}","typeGuard":null,"tryCatchPattern":"// Inside the fallback, branch on cause type:\npublic String fallback(Integer id, Throwable t) {\n    return (t instanceof IllegalArgumentException)\n        ? \"bad request: \" + t.getMessage()\n        : \"degraded\";\n}","preventionTips":["Pass the id parameter when invoking annotated Sentinel resources.","When rules look stale with the file datasource, verify reload happened before debugging code.","Return structured degradation payloads from fallback for real services."],"tags":["sentinel","circuit-breaker","fallback","file-datasource","tutorial"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}