{"record":{"id":"786413130543c2f8","repo":"yudaocode/SpringBoot-Labs","slug":"id-786413","errorCode":null,"errorMessage":"id 参数不允许为空","messagePattern":"id 参数不允许为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"lab-46/lab-46-sentinel-demo-nacos/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-nacos/src/main/java/cn/iocoder/springboot/lab46/sentineldemo/controller/DemoController.java#L49-L83","documentation":"Same @SentinelResource fallback demo in lab-46-sentinel-demo-nacos, which loads Sentinel rules from a Nacos config center. Omitting id on GET /demo/annotations_demo throws IllegalArgumentException and the fallback method converts it into the response 'fallback: id 参数不允许为空'.","triggerScenarios":"GET /demo/annotations_demo without an id parameter; requires the Nacos server reachable so rules (and the resource registration) load at startup.","commonSituations":"Nacos-specific failure mode: if the Nacos server is down or namespace/group mismatch, rules never load and developers misinterpret behavior — though for this particular error (parameter validation fallback) Sentinel's annotation fallback still works with default config. Signature/class wiring mistakes are the same as errors 8–9.","solutions":["Provide ?id=1 to exercise the normal path.","Confirm Nacos connectivity (server-addr, namespace, group, dataId) when degradation rules look inactive; check startup logs for the Nacos datasource init result.","Keep fallback signature: same params as resource method plus optional trailing Throwable.","Handle the null id before Sentinel if you prefer Spring's 400 response over the fallback string."],"exampleFix":"// before: fallback receives raw message\npublic String fallback(Integer id, Throwable throwable) {\n    return \"fallback：\" + throwable.getMessage();\n}\n\n// after: differentiate business error from degradation in fallback\npublic String fallback(Integer id, Throwable throwable) {\n    if (throwable instanceof IllegalArgumentException) {\n        return \"bad request: \" + throwable.getMessage();\n    }\n    return \"degraded\";\n}","handlingStrategy":"validation","validationCode":"// Validate at the client before calling:\n// if (!queryParams.containsKey(\"id\")) throw ...;\n// or server-side binding:\npublic String annotationsDemo(@RequestParam Integer id) { ... }","typeGuard":null,"tryCatchPattern":"public String fallback(Integer id, Throwable throwable) {\n    if (throwable instanceof IllegalArgumentException) {\n        return \"400: \" + throwable.getMessage();\n    }\n    return \"fallback: degraded\";\n}","preventionTips":["Always send required params to @SentinelResource methods.","Verify Nacos connectivity/namespace when degradation rules seem ignored.","Keep the resource name in rules identical to @SentinelResource value."],"tags":["sentinel","circuit-breaker","fallback","nacos","tutorial"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}