{"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/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/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 is less than minVersion. SupportedVersionRange models the [min,max] feature-version range a broker advertises; the invariant 0 <= minVersion <= maxVersion is fundamental and any violation indicates corrupt or malformed feature metadata. This is a hard precondition check inside the admin/feature-metadata layer.","triggerScenarios":"Constructing SupportedVersionRange(minVersion, maxVersion) directly with bad arguments, or—more commonly—parsing broker-sent FinalizedFeatureRange or SupportedFeatureRange data where the broker advertised an inverted or negative range. Reached during ApiVersionsResponse / finalized feature handling.","commonSituations":"A misbehaving or non-compliant broker (older pre-KIP-554 broker, a proxy, or a mock/stub interceptor) returning feature ranges with negative or swapped min/max; manual construction of feature metadata in tests with swapped arguments; corrupt in-memory state after a partial serialization failure.","solutions":["Verify the broker version is compliant with feature negotiation (KIP-554+) and is a genuine Kafka broker, not a proxy stripping feature data.","If constructing SupportedVersionRange directly, ensure 0 <= minVersion and minVersion <= maxVersion before calling the constructor.","Upgrade brokers and clients to the same Kafka version to avoid malformed feature-range responses from older brokers.","Inspect the broker-side FinalizedFeatureRange / SupportedFeatureRange emission for corruption."],"exampleFix":"// before\nnew SupportedVersionRange((short) 5, (short) 2); // max < min -> throws\n\n// after\nnew SupportedVersionRange((short) 2, (short) 5);","handlingStrategy":"validation","validationCode":"// Validate version bounds before constructing SupportedVersionRange:\nshort minVersion = ..., maxVersion = ...;\nif (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {\n    throw new IllegalArgumentException(\"Refusing to build SupportedVersionRange with min=\" + minVersion + \", max=\" + maxVersion);\n}\nnew SupportedVersionRange(minVersion, maxVersion);","typeGuard":"static boolean isValidVersionRange(short minVersion, short maxVersion) {\n    return minVersion >= 0 && maxVersion >= 0 && maxVersion >= minVersion;\n}","tryCatchPattern":"try {\n    new SupportedVersionRange(minVersion, maxVersion);\n} catch (IllegalArgumentException e) {\n    // clamp or reject; this usually indicates corrupt metadata from the broker\n    throw new RuntimeException(\"Unsupported feature version range received\", e);\n}","preventionTips":["This class is rarely constructed by application code - it represents broker-advertised feature versions. If you are constructing it, double-check the source of minVersion/maxVersion.","Treat any occurrence as a broker/protocol data integrity problem, not a user-input problem.","When persisting or forwarding version ranges, preserve both fields together to avoid min/max drift."],"tags":["admin-api","feature-metadata","validation","precondition","java"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}