{"record":{"id":"0c98d495c2d34575","repo":"MyCATApache/Mycat-Server","slug":"rulerequired-but-rule-is-null","errorCode":null,"errorMessage":"ruleRequired but rule is null","messagePattern":"ruleRequired but rule is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/model/TableConfig.java","lineNumber":82,"sourceCode":"    private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(false);\n\n    public TableConfig(String tableName, String primaryKey, boolean autoIncrement, boolean needAddLimit, int tableType,\n                       String dataNode, Set<String> dbType, RuleConfig rule, boolean ruleRequired,\n                       TableConfig parentTC, boolean isChildTable, String joinKey,\n                       String parentKey, String subTables, boolean fetchStoreNodeByJdbc) {\n        if (tableName == null) {\n            throw new IllegalArgumentException(\"table name is null\");\n        } else if (dataNode == null) {\n            throw new IllegalArgumentException(\"dataNode name is null\");\n        }\n        this.primaryKey = primaryKey;\n        this.autoIncrement = autoIncrement;\n        this.needAddLimit = needAddLimit;\n        this.fetchStoreNodeByJdbc = fetchStoreNodeByJdbc;\n        this.tableType = tableType;\n        this.dbTypes = dbType;\n        if (ruleRequired && rule == null) {\n            throw new IllegalArgumentException(\"ruleRequired but rule is null\");\n        }\n\n        this.name = tableName.toUpperCase();\n        String theDataNodes[] = SplitUtil.split(dataNode, ',', '$', '-');\n        if (theDataNodes == null || theDataNodes.length <= 0) {\n            throw new IllegalArgumentException(\"invalid table dataNodes: \" + dataNode);\n        }\n        dataNodes = new ArrayList<String>(theDataNodes.length);\n        for (String dn : theDataNodes) {\n            dataNodes.add(dn);\n        }\n\n        if (subTables != null && !subTables.equals(\"\")) {\n            String sTables[] = SplitUtil.split(subTables, ',', '$', '-');\n            if (sTables == null || sTables.length <= 0) {\n                throw new IllegalArgumentException(\"invalid table subTables\");\n            }\n            this.distTables = new ArrayList<String>(sTables.length);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/model/TableConfig.java#L64-L100","documentation":"TableConfig enforces consistency between the ruleRequired flag and the sharding rule: if ruleRequired is true, a RuleConfig must be supplied. When ruleRequired is true but rule is null, IllegalArgumentException is thrown, because a table declared to require a rule cannot be routed without one.","triggerScenarios":"new TableConfig(..., ruleRequired=true, rule=null, ...) — e.g. a <table> element declaring ruleRequired but the referenced tableRule/function is missing or failed to load.","commonSituations":"schema.xml table with ruleRequired=\"true\" but no rule attribute; the rule's function name not matching any function defined in rule.xml; rule loading failure earlier in startup.","solutions":["Set the rule attribute on the <table> element to a defined tableRule name.","Ensure the function referenced by the tableRule exists in rule.xml.","If the table truly has no sharding rule, set ruleRequired=\"false\" on the table element."],"exampleFix":"// before (schema.xml)\n<table name=\"orders\" dataNode=\"dn1\" ruleRequired=\"true\" />\n// after\n<table name=\"orders\" dataNode=\"dn1\" rule=\"order-rule\" ruleRequired=\"true\" />","handlingStrategy":"validation","validationCode":"if (ruleRequired && rule == null) throw new IllegalArgumentException(\"table \" + tableName + \" sets ruleRequired but has no rule\");","typeGuard":null,"tryCatchPattern":"try { new TableConfig(...); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"ruleRequired\")) { LOG.error(\"Add rule attr or set ruleRequired=false\"); } throw e; }","preventionTips":["Only set ruleRequired=\"true\" on tables that actually declare a rule attribute.","Verify the referenced tableRule and its function load successfully at startup.","Keep rule.xml and schema.xml in sync under version control."],"tags":["config","mycat","rule","sharding"],"backgroundTag":"missing-required-config-field","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"}