MyCATApache/Mycat-Server · error · IllegalArgumentException

no rule is found

Error message

no rule is found

What it means

TableRuleConfig's constructor throws IllegalArgumentException when the RuleConfig argument is null. The library requires every named table rule to have a non-null rule object, so a null rule is rejected immediately at construction time. This fails fast rather than allowing a half-initialized table rule to break routing later.

Solutions

  1. Check that the RuleConfig passed to the constructor is non-null before constructing TableRuleConfig
  2. Verify the rule referenced in schema.xml exists and was successfully parsed from rule.xml
  3. Fix any earlier load failure (check logs/warnings during rule loading) that left the RuleConfig null

Example fix

// before
TableRuleConfig trc = new TableRuleConfig("order", ruleMap.get("orderRule")); // null if key missing
// after
RuleConfig rc = ruleMap.get("orderRule");
if (rc == null) { throw new ConfigException("rule 'orderRule' not defined in rule.xml"); }
TableRuleConfig trc = new TableRuleConfig("order", rc);
Defensive patterns

Strategy: validation

Validate before calling

if (rule == null) { throw new ConfigException("table '" + name + "' has no matching rule; check rule.xml"); }
TableRuleConfig trc = new TableRuleConfig(name, rule);

Try / catch

try { new TableRuleConfig(name, rule); } catch (IllegalArgumentException e) { log.error("bad table rule: {}", e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Calling new TableRuleConfig(name, null) — e.g. when building a table rule programmatically or when config parsing produced a RuleConfig object that was null but a name was present.

Common situations: schema.xml / rule.xml misconfiguration where a <table> references a rule name that failed to load; initialization code passing an uninitialized RuleConfig; unit tests constructing rules manually.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/8313c60bf2eb10bd. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/model/rule/TableRuleConfig.java:41

 */
package io.mycat.config.model.rule;

import java.io.Serializable;

/**
 * @author mycat
 */
public class TableRuleConfig implements Serializable {
    private  String name;
    private final RuleConfig rule;

    public TableRuleConfig(String name, RuleConfig rule) {
        if (name == null) {
            throw new IllegalArgumentException("name is null");
        }
        this.name = name;
        if (rule == null) {
            throw new IllegalArgumentException("no rule is found");
        }
        this.rule =rule;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return unmodifiable
     */
    public RuleConfig getRule() {
        return rule;
    }

View on GitHub (pinned to 65f8d8beb7)