{"id":"961a7361efcb0f8a","repo":"apache/kafka","slug":"expected-minversionlevel-0-maxversionlevel","errorCode":null,"errorMessage":"Expected minVersionLevel >= 0, maxVersionLevel >= 0 and maxVersionLevel >= minVersionLevel, but received minVersionLevel: %d, maxVersionLevel: %d","messagePattern":"Expected minVersionLevel >= 0, maxVersionLevel >= 0 and maxVersionLevel >= minVersionLevel, but received minVersionLevel: (.+?), maxVersionLevel: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/FinalizedVersionRange.java","lineNumber":44,"sourceCode":" */\n@InterfaceAudience.Public\npublic class FinalizedVersionRange {\n    private final short minVersionLevel;\n\n    private final short maxVersionLevel;\n\n    /**\n     * Raises an exception unless the following condition is met:\n     * {@code minVersionLevel >= 1} and {@code maxVersionLevel >= 1} and {@code maxVersionLevel >= minVersionLevel}.\n     *\n     * @param minVersionLevel   The minimum version level value.\n     * @param maxVersionLevel   The maximum version level value.\n     *\n     * @throws IllegalArgumentException   Raised when the condition described above is not met.\n     */\n    public FinalizedVersionRange(final short minVersionLevel, final short maxVersionLevel) {\n        if (minVersionLevel < 0 || maxVersionLevel < 0 || maxVersionLevel < minVersionLevel) {\n            throw new IllegalArgumentException(\n                String.format(\n                    \"Expected minVersionLevel >= 0, maxVersionLevel >= 0 and\" +\n                    \" maxVersionLevel >= minVersionLevel, but received\" +\n                    \" minVersionLevel: %d, maxVersionLevel: %d\", minVersionLevel, maxVersionLevel));\n        }\n        this.minVersionLevel = minVersionLevel;\n        this.maxVersionLevel = maxVersionLevel;\n    }\n\n    public short minVersionLevel() {\n        return minVersionLevel;\n    }\n\n    public short maxVersionLevel() {\n        return maxVersionLevel;\n    }\n\n    @Override","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/admin/FinalizedVersionRange.java#L26-L62","documentation":"Thrown by the FinalizedVersionRange constructor when the supplied minVersionLevel/maxVersionLevel pair fails any of: minVersionLevel >= 0, maxVersionLevel >= 0, or maxVersionLevel >= minVersionLevel. This invariant defines a valid non-negative, ordered version range for a finalized feature across the cluster. Note the Javadoc mentions >= 1 historically but the code enforces >= 0; either way the message names the exact failed condition.","triggerScenarios":"Constructing new FinalizedVersionRange(min, max) with a negative min or max, or with min > max. Reached from code that builds a finalized feature range from computed values, external config, or deserialized controller data without prior validation.","commonSituations":"Caller computes min/max from subtractions that underflow; swap of min and max arguments; external config feeding negative or inverted numbers; tests using placeholder literals; corrupted metadata being reconstructed client-side.","solutions":["Ensure both levels are >= 0 (typically >= 1 for real features) and that max >= min before constructing.","Swap the arguments if you accidentally passed them in the wrong order (the message tells you which is which).","Validate and clamp external input before constructing the range.","Add a guard clause or precondition (e.g. checkArgument) upstream so the error is caught earlier."],"exampleFix":"// before - args swapped / out of range\nnew FinalizedVersionRange((short) 5, (short) 2);\nnew FinalizedVersionRange((short) -1, (short) 3);\n\n// after - valid non-negative ordered range\nnew FinalizedVersionRange((short) 2, (short) 5);","handlingStrategy":"validation","validationCode":"// FinalizedVersionRange requires min>=0, max>=0, max>=min.\nshort minVersionLevel = ...;\nshort maxVersionLevel = ...;\nif (minVersionLevel < 0 || maxVersionLevel < 0 || maxVersionLevel < minVersionLevel) {\n    throw new IllegalArgumentException(String.format(\n        \"Invalid FinalizedVersionRange: min=%d max=%d\", minVersionLevel, maxVersionLevel));\n}\nFinalizedVersionRange range = new FinalizedVersionRange(minVersionLevel, maxVersionLevel);","typeGuard":"// Predicate narrowing a (short, short) pair to a range-safe value.\nstatic boolean isValidVersionRange(short min, short max) {\n    return min >= 0 && max >= 0 && max >= min;\n}","tryCatchPattern":"try {\n    FinalizedVersionRange range = new FinalizedVersionRange(minVersionLevel, maxVersionLevel);\n} catch (IllegalArgumentException e) {\n    // Inverted or negative range. Swap if inverted, clamp to 0 if negative, or reject.\n    log.error(\"Invalid FinalizedVersionRange({}, {}): {}\",\n        minVersionLevel, maxVersionLevel, e.getMessage());\n}","preventionTips":["Validate min/max ordering at the config boundary before constructing FinalizedVersionRange.","Wrap construction in a factory that enforces min>=0, max>=0, max>=min in one place.","When reading levels from user input, parse to int first, range-check, then narrow to short.","Unit-test boundary cases (0,0), (1,1), (1, Short.MAX_VALUE), and the inverted (2,1)."],"tags":["admin-client","feature-versioning","api-misuse","illegal-argument","input-validation","metadata"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}