apache/kafka · error · IllegalArgumentException
Expected 0 <= minVersion <= maxVersion but received minVersi
Error message
Expected 0 <= minVersion <= maxVersion but received minVersion:%d, maxVersion:%d.
What it means
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.
Source
Thrown at clients/src/main/java/org/apache/kafka/clients/admin/SupportedVersionRange.java:44
*/
@InterfaceAudience.Public
public class SupportedVersionRange {
private final short minVersion;
private final short maxVersion;
/**
* Raises an exception unless the following conditions are met:
* 0 <= minVersion <= maxVersion.
*
* @param minVersion The minimum version value.
* @param maxVersion The maximum version value.
*
* @throws IllegalArgumentException Raised when the condition described above is not met.
*/
public SupportedVersionRange(final short minVersion, final short maxVersion) {
if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {
throw new IllegalArgumentException(
String.format(
"Expected 0 <= minVersion <= maxVersion but received minVersion:%d, maxVersion:%d.",
minVersion,
maxVersion));
}
this.minVersion = minVersion;
this.maxVersion = maxVersion;
}
public short minVersion() {
return minVersion;
}
public short maxVersion() {
return maxVersion;
}
@OverrideView on GitHub (pinned to c31c9215e1)
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.
Example fix
// before new SupportedVersionRange((short) 5, (short) 2); // max < min -> throws // after new SupportedVersionRange((short) 2, (short) 5);
Defensive patterns
Strategy: validation
Validate before calling
// Validate version bounds before constructing SupportedVersionRange:
short minVersion = ..., maxVersion = ...;
if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {
throw new IllegalArgumentException("Refusing to build SupportedVersionRange with min=" + minVersion + ", max=" + maxVersion);
}
new SupportedVersionRange(minVersion, maxVersion); Type guard
static boolean isValidVersionRange(short minVersion, short maxVersion) {
return minVersion >= 0 && maxVersion >= 0 && maxVersion >= minVersion;
} Try / catch
try {
new SupportedVersionRange(minVersion, maxVersion);
} catch (IllegalArgumentException e) {
// clamp or reject; this usually indicates corrupt metadata from the broker
throw new RuntimeException("Unsupported feature version range received", e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Member {member} was not included in the original request
- Unknown topology description status id: {id}
- Topic partitions to assign to cannot have null or empty topi
- RebalanceListener cannot be null
- Topic pattern to subscribe to cannot be null
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/1b7b4d99c5575aec.json.
Report an issue: GitHub.