{"record":{"id":"41181d0e0928bbf2","repo":"apache/dubbo","slug":"route-rule-can-not-be-empty","errorCode":null,"errorMessage":"route rule can not be empty.","messagePattern":"route rule can not be empty\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java","lineNumber":115,"sourceCode":"            function = compilable.compile(rule);\n        } catch (ScriptException e) {\n            logger.error(\n                    CLUSTER_SCRIPT_EXCEPTION,\n                    \"script route rule invalid\",\n                    \"\",\n                    \"script route error, rule has been ignored. rule: \" + rule + \", url: \"\n                            + RpcContext.getServiceContext().getUrl(),\n                    e);\n        }\n    }\n\n    /**\n     * get rule from url parameters.\n     */\n    private String getRule(URL url) {\n        String vRule = url.getParameterAndDecoded(RULE_KEY);\n        if (StringUtils.isEmpty(vRule)) {\n            throw new IllegalStateException(\"route rule can not be empty.\");\n        }\n        return vRule;\n    }\n\n    /**\n     * create ScriptEngine instance by type from url parameters, then cache it\n     */\n    private ScriptEngine getEngine(URL url) {\n        String type = url.getParameter(TYPE_KEY, DEFAULT_SCRIPT_TYPE_KEY);\n\n        return ConcurrentHashMapUtils.computeIfAbsent(ENGINES, type, t -> {\n            ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName(type);\n            if (scriptEngine == null) {\n                throw new IllegalStateException(\"unsupported route engine type: \" + type);\n            }\n            return scriptEngine;\n        });\n    }","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java#L97-L133","documentation":"Thrown by ScriptStateRouter.getRule() when the script router's 'rule' URL parameter is empty. The script router evaluates a scripting-language rule to filter invokers; enabling/configuring it without a rule body is invalid. Thrown at router construction time.","triggerScenarios":"Configuring the script state router (SPI 'script') with a router URL whose 'rule' parameter is missing/empty. getRule(url) reads url.getParameterAndDecoded(RULE_KEY) and rejects blank values.","commonSituations":"Publishing a script routing rule that omits the script body; URL-encoding problems stripping the rule; copying a router URL template and forgetting to fill in the rule.","solutions":["Provide a non-empty script rule, e.g. rule: 'function invoke(invokers, invocation) { return invokers; }' for the javascript engine.","If you do not need script routing, remove the script router URL or disable it.","Ensure the rule value survives URL-encoding when stored in the registry."],"exampleFix":"# before (broken): script router with no rule\nscript://0.0.0.0/...?type=javascript\n\n# after\nscript://0.0.0.0/...?type=javascript&rule=function%20invoke(invokers%2Cinvocation)%7B%20return%20invokers%3B%20%7D","handlingStrategy":"validation","validationCode":"// Validate script router rule before constructing\nString rule = url.getParameterAndDecoded(RULE_KEY);\nif (StringUtils.isEmpty(rule)) {\n    throw new IllegalArgumentException(\n        \"Script router requires a non-empty 'rule' parameter; provide a script or remove the router.\");\n}\nreturn new ScriptStateRouter<>(url);","typeGuard":null,"tryCatchPattern":"try {\n    new ScriptStateRouter<>(url);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"route rule can not be empty\")) {\n        log.error(\"Script router has no rule; skipping it\");\n        // omit this router from the chain\n    } else throw e;\n}","preventionTips":["Always provide a non-empty script rule for the script router.","URL-encode the rule so it is not truncated in the registry.","Remove the script router URL entirely if you do not need it."],"tags":["router","script","config","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}