MyCATApache/Mycat-Server · error · IllegalArgumentException
functionName is null
Error message
functionName is null
What it means
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.
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.
Example fix
// before (rule.xml) <tableRule name="order-rule"><rule><columns>id</columns></rule></tableRule> // after <tableRule name="order-rule"><rule><columns>id</columns><function>mod-long</function></rule></tableRule>
Defensive patterns
Strategy: validation
Validate before calling
if (functionName == null || functionName.isEmpty()) throw new IllegalArgumentException("rule function attribute required"); Try / catch
try { new RuleConfig(column, fn); } catch (IllegalArgumentException e) { if ("functionName is null".equals(e.getMessage())) { LOG.error("rule missing function attr"); } throw e; } Prevention
- 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.
When it happens
Trigger: new RuleConfig(column, null) or rule.xml parsing where a tableRule's rule element has no function attribute (attribute resolves to null).
Common situations: rule.xml <rule> element missing the function attribute; programmatic rule construction omitting the function name; XML loader returning null for an empty attribute value.
Related errors
- name is null
- table name is null
- dataNode name is null
- ruleRequired but rule is null
- no rule column is found
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/d0a4fff9e4e5d0a0.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/model/rule/RuleConfig.java:41
*/
package io.mycat.config.model.rule;
import io.mycat.route.function.AbstractPartitionAlgorithm;
import java.io.Serializable;
/**
* 分片规则,column是用于分片的数据库物理字段
* @author mycat
*/
public class RuleConfig implements Serializable {
private final String column;
private final String functionName;
private AbstractPartitionAlgorithm ruleAlgorithm;
public RuleConfig(String column, String functionName) {
if (functionName == null) {
throw new IllegalArgumentException("functionName is null");
}
this.functionName = functionName;
if (column == null || column.length() <= 0) {
throw new IllegalArgumentException("no rule column is found");
}
this.column = column;
}
public AbstractPartitionAlgorithm getRuleAlgorithm() {
return ruleAlgorithm;
}
public void setRuleAlgorithm(AbstractPartitionAlgorithm ruleAlgorithm) {
this.ruleAlgorithm = ruleAlgorithm;
View on GitHub (pinned to 65f8d8beb7)