{"record":{"id":"faba8fc0131152a8","repo":"MyCATApache/Mycat-Server","slug":"error-check-your-scope-scopelength-definition","errorCode":null,"errorMessage":"error,check your scope & scopeLength definition.","messagePattern":"error,check your scope & scopeLength definition\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/PartitionUtil.java","lineNumber":54,"sourceCode":"    private static final int PARTITION_LENGTH = 1024;\n\n    // %转换为&操作的换算数值\n    private static final long AND_VALUE = PARTITION_LENGTH - 1;\n\n    // 分区线段\n    private final int[] segment = new int[PARTITION_LENGTH];\n\n    /**\n     * <pre>\n     * @param count 表示定义的分区数\n     * @param length 表示对应每个分区的取值长度\n     * 注意：其中count,length两个数组的长度必须是一致的。\n     * 约束：1024 = sum((count[i]*length[i])). count和length两个向量的点积恒等于1024\n     * </pre>\n     */\n    public PartitionUtil(int[] count, int[] length) {\n        if (count == null || length == null || (count.length != length.length)) {\n            throw new RuntimeException(\"error,check your scope & scopeLength definition.\");\n        }\n        int segmentLength = 0;\n        for (int i = 0; i < count.length; i++) {\n            segmentLength += count[i];\n        }\n        int[] ai = new int[segmentLength + 1];\n\n        int index = 0;\n        for (int i = 0; i < count.length; i++) {\n            for (int j = 0; j < count[i]; j++) {\n                ai[++index] = ai[index - 1] + length[i];\n            }\n        }\n        if (ai[ai.length - 1] != PARTITION_LENGTH) {\n            throw new RuntimeException(\"error,check your partitionScope definition.\");\n        }\n\n        // 数据映射操作","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/PartitionUtil.java#L36-L72","documentation":"PartitionUtil computes a hash-partition mapping from paired count[] and length[] arrays whose dot product must equal the total range (e.g. 1024). The constructor throws RuntimeException if either array is null or their lengths differ, since the partition definition is malformed.","triggerScenarios":"new PartitionUtil(count, length) with count == null, length == null, or count.length != length.length.","commonSituations":"Mis-edited partition function config in rule.xml/partition definitions where one array has more entries than the other; programmatically built arrays where one list is filtered/empty.","solutions":["Fix the partition config so count and length arrays have the same number of elements.","Also verify sum(count[i]*length[i]) equals the expected total range (e.g. 1024) to avoid later mapping errors.","Add a config sanity check at startup that validates array presence and equal lengths."],"exampleFix":"// before\nint[] count = {4};\nint[] length = {256, 256}; // lengths differ -> throw\n// after\nint[] count = {4, 4};\nint[] length = {256, 256}; // equal lengths, 4*256+4*256 = 2048... adjust to constraint","handlingStrategy":"validation","validationCode":"if (count == null || length == null || count.length != length.length) {\n    throw new IllegalArgumentException(\"count and length arrays must be non-null and of equal length\");\n}","typeGuard":null,"tryCatchPattern":"try { PartitionUtil p = new PartitionUtil(count, length); } catch (RuntimeException e) { throw new ConfigException(\"bad partition definition\", e); }","preventionTips":["Validate partition rule.xml arrays (equal lengths, dot product = 1024) at startup","Unit-test partition configs before deployment","Generate count/length arrays from one config source to avoid drift"],"tags":["java","partitioning","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}