{"record":{"id":"8d33dde28c2321b0","repo":"apache/seatunnel","slug":"illegal-value-of-num","errorCode":null,"errorMessage":"Illegal value of num","messagePattern":"Illegal value of num","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-tidb/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/tidb/source/utils/TableKeyRangeUtils.java","lineNumber":39,"sourceCode":"import org.tikv.common.util.KeyRangeUtils;\nimport org.tikv.kvproto.Coprocessor.KeyRange;\n\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\n\n/** Utils to obtain the keyRange of table. */\npublic class TableKeyRangeUtils {\n    public static KeyRange getTableKeyRange(final long tableId) {\n        return KeyRangeUtils.makeCoprocRange(\n                RowKey.createMin(tableId).toByteString(),\n                RowKey.createBeyondMax(tableId).toByteString());\n    }\n\n    public static List<KeyRange> getTableKeyRanges(final long tableId, final int num) {\n        if (num <= 0) {\n            throw new IllegalArgumentException(\"Illegal value of num\");\n        }\n\n        if (num == 1) {\n            return Collections.singletonList(getTableKeyRange(tableId));\n        }\n\n        final long delta =\n                BigInteger.valueOf(Long.MAX_VALUE)\n                        .subtract(BigInteger.valueOf(Long.MIN_VALUE + 1))\n                        .divide(BigInteger.valueOf(num))\n                        .longValueExact();\n        final List<KeyRange> keyRanges = new ArrayList<>(num);\n        for (int i = 0; i < num; i++) {\n            final RowKey startKey =\n                    (i == 0)\n                            ? RowKey.createMin(tableId)\n                            : RowKey.toRowKey(tableId, Long.MIN_VALUE + delta * i);\n            final RowKey endKey =","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-tidb/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/tidb/source/utils/TableKeyRangeUtils.java#L21-L57","documentation":"getTableKeyRanges validates that the requested number of key ranges for a table is positive; num <= 0 cannot produce a sane range partitioning (num==1 yields the full table range). Thrown as IllegalArgumentException before any range computation begins.","triggerScenarios":"Calling TableKeyRangeUtils.getTableKeyRanges(tableId, num) with num = 0 or negative — usually from a miscomputed parallelism/split-count derived from configuration (e.g. parallelism resolved to 0).","commonSituations":"A config option like scan.parallelism or increment.parallelism set to 0 or left unset and defaulted badly; arithmetic producing 0 ranges (e.g. splitting by byte size with tiny tables).","solutions":["Check the connector config that feeds the split/parallelism count and set it to >= 1","Fix the caller's computation to clamp to Math.max(1, computedRanges)","Validate user-supplied parallelism options before job submission","If this arises from internal math, log the inputs (tableId, num) and correct the divisor"],"exampleFix":"// before\nint num = tableSizeBytes / splitSizeBytes; // 0 for tiny tables\nList<KeyRange> ranges = TableKeyRangeUtils.getTableKeyRanges(tableId, num);\n// after\nint num = Math.max(1, (int) (tableSizeBytes / splitSizeBytes));\nList<KeyRange> ranges = TableKeyRangeUtils.getTableKeyRanges(tableId, num);","handlingStrategy":"validation","validationCode":"int num = computeRangeCount(config);\nif (num <= 0) {\n    throw new IllegalArgumentException(\"Range count must be >= 1, got \" + num + \"; check parallelism config\");\n}\nList<KeyRange> ranges = TableKeyRangeUtils.getTableKeyRanges(tableId, num);","typeGuard":null,"tryCatchPattern":"try {\n    ranges = TableKeyRangeUtils.getTableKeyRanges(tableId, num);\n} catch (IllegalArgumentException e) {\n    LOG.warn(\"Illegal num={}, falling back to single full-table range\", num);\n    ranges = TableKeyRangeUtils.getTableKeyRange(tableId);\n}","preventionTips":["Clamp computed split counts with Math.max(1, n)","Validate parallelism/split-size config options are >= 1 at job submission","Log the divisor inputs when computing range counts from table size"],"tags":["tidb","key-range","argument-validation","split-generation"],"backgroundTag":"argument-out-of-range","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}