{"record":{"id":"1b7b4d99c5575aec","repo":"apache/kafka","slug":"expected-0-minversion-maxversion-but-receive","errorCode":null,"errorMessage":"Expected 0 <= minVersion <= maxVersion but received minVersion:%d, maxVersion:%d.","messagePattern":"Expected 0 <= minVersion <= maxVersion but received minVersion:(.+?), maxVersion:(.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/SupportedVersionRange.java","lineNumber":44,"sourceCode":" */\n@InterfaceAudience.Public\npublic class SupportedVersionRange {\n    private final short minVersion;\n\n    private final short maxVersion;\n\n    /**\n     * Raises an exception unless the following conditions are met:\n     *  0 &lt;= minVersion &lt;= maxVersion.\n     *\n     * @param minVersion           The minimum version value.\n     * @param maxVersion           The maximum version value.\n     *\n     * @throws IllegalArgumentException   Raised when the condition described above is not met.\n     */\n    public SupportedVersionRange(final short minVersion, final short maxVersion) {\n        if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {\n            throw new IllegalArgumentException(\n                String.format(\n                    \"Expected 0 <= minVersion <= maxVersion but received minVersion:%d, maxVersion:%d.\",\n                    minVersion,\n                    maxVersion));\n        }\n        this.minVersion = minVersion;\n        this.maxVersion = maxVersion;\n    }\n\n    public short minVersion() {\n        return minVersion;\n    }\n\n    public short maxVersion() {\n        return maxVersion;\n    }\n\n    @Override","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/SupportedVersionRange.java#L26-L62","documentation":"Thrown by the SupportedVersionRange constructor when minVersion or maxVersion is negative, or when maxVersion < minVersion. SupportedVersionRange is a value object describing a contiguous inclusive range of protocol/feature versions and is invariant-closed under ordering.","triggerScenarios":"Calling `new SupportedVersionRange((short) -1, (short) 5)`, `new SupportedVersionRange((short) 5, (short) 3)`, or `new SupportedVersionRange((short) 0, (short) -1)`.","commonSituations":"Parsing version metadata from a malformed config/JSON where negatives or swapped min/max were stored; deserializing a corrupted response payload; computing version ranges from an off-by-one algorithm.","solutions":["Validate before construction: `if (min < 0 || max < 0 || max < min) throw ...` with a domain-meaningful message.","Sanitize the source data: clamp negatives to 0 and swap min/max if inverted only if business logic permits.","Inspect the upstream producer of the version numbers (e.g. feature flag service, API contract)."],"exampleFix":"// before\nnew SupportedVersionRange(minVersion, maxVersion);\n\n// after\nif (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {\n    throw new IllegalArgumentException(\"Bad version range min=\" + minVersion + \" max=\" + maxVersion);\n}\nnew SupportedVersionRange(minVersion, maxVersion);","handlingStrategy":"validation","validationCode":"if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {\n    throw new IllegalArgumentException(\"Invalid version range min=\" + minVersion + \" max=\" + maxVersion);\n}\nnew SupportedVersionRange(minVersion, maxVersion);","typeGuard":"static boolean isValidRange(short min, short max) {\n    return min >= 0 && max >= 0 && max >= min;\n}","tryCatchPattern":"try {\n    return new SupportedVersionRange(min, max);\n} catch (IllegalArgumentException e) {\n    log.error(\"Bad version range from upstream: min={}, max={}\", min, max);\n    throw e;\n}","preventionTips":["Validate version metadata at the boundary where it enters your program (config, RPC, file).","Add unit tests covering negative, inverted, and zero-range inputs.","Document SupportedVersionRange invariants for downstream callers."],"tags":["admin-client","feature-versions","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}