{"record":{"id":"d0a4fff9e4e5d0a0","repo":"MyCATApache/Mycat-Server","slug":"functionname-is-null","errorCode":null,"errorMessage":"functionName is null","messagePattern":"functionName is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/model/rule/RuleConfig.java","lineNumber":41,"sourceCode":" */\r\npackage io.mycat.config.model.rule;\r\n\r\nimport io.mycat.route.function.AbstractPartitionAlgorithm;\r\n\r\nimport java.io.Serializable;\r\n\r\n/**\r\n * 分片规则，column是用于分片的数据库物理字段\r\n * @author mycat\r\n */\r\npublic class RuleConfig implements Serializable {\r\n\tprivate final String column;\r\n\tprivate final String functionName;\r\n\tprivate AbstractPartitionAlgorithm ruleAlgorithm;\r\n\r\n\tpublic RuleConfig(String column, String functionName) {\r\n\t\tif (functionName == null) {\r\n\t\t\tthrow new IllegalArgumentException(\"functionName is null\");\r\n\t\t}\r\n\t\tthis.functionName = functionName;\r\n\t\tif (column == null || column.length() <= 0) {\r\n\t\t\tthrow new IllegalArgumentException(\"no rule column is found\");\r\n\t\t}\r\n\t\tthis.column = column;\r\n\t}\r\n\r\n\t\r\n\r\n\tpublic AbstractPartitionAlgorithm getRuleAlgorithm() {\r\n\t\treturn ruleAlgorithm;\r\n\t}\r\n\r\n\r\n\r\n\tpublic void setRuleAlgorithm(AbstractPartitionAlgorithm ruleAlgorithm) {\r\n\t\tthis.ruleAlgorithm = ruleAlgorithm;\r","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/model/rule/RuleConfig.java#L23-L59","documentation":"RuleConfig's constructor requires a non-null functionName — the name of the partition algorithm (function) that implements the sharding rule. If functionName is null, IllegalArgumentException(\"functionName is null\") is thrown immediately, since a rule without an algorithm name is unusable.","triggerScenarios":"new RuleConfig(column, null) or rule.xml parsing where a tableRule's rule element has no function attribute (attribute resolves to null).","commonSituations":"rule.xml <rule> element missing the function attribute; programmatic rule construction omitting the function name; XML loader returning null for an empty attribute value.","solutions":["Add function=\"<algorithmName>\" to the <rule> element in rule.xml.","Ensure the algorithm name matches a <function name=...> defined in rule.xml.","If constructing RuleConfig programmatically, pass a non-null function name string."],"exampleFix":"// before (rule.xml)\n<tableRule name=\"order-rule\"><rule><columns>id</columns></rule></tableRule>\n// after\n<tableRule name=\"order-rule\"><rule><columns>id</columns><function>mod-long</function></rule></tableRule>","handlingStrategy":"validation","validationCode":"if (functionName == null || functionName.isEmpty()) throw new IllegalArgumentException(\"rule function attribute required\");","typeGuard":null,"tryCatchPattern":"try { new RuleConfig(column, fn); } catch (IllegalArgumentException e) { if (\"functionName is null\".equals(e.getMessage())) { LOG.error(\"rule missing function attr\"); } throw e; }","preventionTips":["Every <rule> element in rule.xml must have a function attribute.","Cross-check function names against <function> definitions in the same file.","Validate rule.xml at build time."],"tags":["config","mycat","rule","null-argument"],"backgroundTag":"null-argument","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}