{"record":{"id":"25eb72bfdc581f36","repo":"alibaba/canal","slug":"clusterid-and-serverid-are-all-empty","errorCode":null,"errorMessage":"clusterId and serverId are all empty","messagePattern":"clusterId and serverId are all empty","errorType":"validation","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/CanalConfigServiceImpl.java","lineNumber":50,"sourceCode":"    private static final String CANAL_ADAPTER_CONFIG = \"application.yml\";\n\n    public CanalConfig getCanalConfig(Long clusterId, Long serverId) {\n        CanalConfig config = null;\n        if (clusterId != null && clusterId != 0) {\n            config = CanalConfig.find.query().where().eq(\"clusterId\", clusterId).findOne();\n        } else if (serverId != null && serverId != 0) {\n            config = CanalConfig.find.query().where().eq(\"serverId\", serverId).findOne();\n            if (config == null) {\n                NodeServer nodeServer = NodeServer.find.byId(serverId);\n                if (nodeServer != null) {\n                    Long cid = nodeServer.getClusterId();\n                    if (cid != null) {\n                        config = CanalConfig.find.query().where().eq(\"clusterId\", cid).findOne();\n                    }\n                }\n            }\n        } else {\n            throw new ServiceException(\"clusterId and serverId are all empty\");\n        }\n        if (config == null) {\n            config = new CanalConfig();\n            config.setName(CANAL_GLOBAL_CONFIG);\n            return config;\n        }\n\n        return config;\n    }\n\n    public CanalConfig getCanalConfigSummary() {\n        return CanalConfig.find.query()\n            .setDisableLazyLoading(true)\n            .select(\"name, modifiedTime\")\n            .where()\n            .eq(\"id\", 1L)\n            .findOne();\n    }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/CanalConfigServiceImpl.java#L32-L68","documentation":"Thrown by CanalConfigServiceImpl when neither a valid clusterId nor a non-zero serverId is supplied. The lookup branches on clusterId first, then serverId; the else branch rejects an ambiguous/empty request.","triggerScenarios":"Requesting canal config with clusterId null/0 AND serverId null/0 (or serverId == 0). Both branches are skipped and the else throws 'clusterId and serverId are all empty'.","commonSituations":"UI/API call omitted both identifiers; client sent serverId=0 (treated as empty by the != 0 guard); a malformed request after a cluster+server were both deselected.","solutions":["Provide either a valid clusterId or a non-zero serverId in the request.","Ensure serverId is not 0 (the code treats serverId != 0 as the active condition).","Validate the request payload before calling the service method.","Check the UI form binding actually sends the selected cluster/server id."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if ((clusterId == null || clusterId == 0) && (serverId == null || serverId == 0)) {\n    throw new IllegalArgumentException(\"Either clusterId or a non-zero serverId must be provided\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the request has a non-zero clusterId or serverId client-side.","Treat serverId == 0 as absent (the service does).","Add UI form validation requiring one identifier."],"tags":["canal-admin","validation","config","request-params"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}