apache/kafka · error · IllegalArgumentException
Expected 0 <= minVersion <= maxVersion but received…
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 < minVersion. SupportedVersionRange is a value object describing a contiguous inclusive range of protocol/feature versions and is invariant-closed under ordering.
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).
Example fix
// before
new SupportedVersionRange(minVersion, maxVersion);
// after
if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {
throw new IllegalArgumentException("Bad version range min=" + minVersion + " max=" + maxVersion);
}
new SupportedVersionRange(minVersion, maxVersion); Defensive patterns
Strategy: validation
Validate before calling
if (minVersion < 0 || maxVersion < 0 || maxVersion < minVersion) {
throw new IllegalArgumentException("Invalid version range min=" + minVersion + " max=" + maxVersion);
}
new SupportedVersionRange(minVersion, maxVersion); Type guard
static boolean isValidRange(short min, short max) {
return min >= 0 && max >= 0 && max >= min;
} Try / catch
try {
return new SupportedVersionRange(min, max);
} catch (IllegalArgumentException e) {
log.error("Bad version range from upstream: min={}, max={}", min, max);
throw e;
} Prevention
- 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.
When it happens
Trigger: Calling `new SupportedVersionRange((short) -1, (short) 5)`, `new SupportedVersionRange((short) 5, (short) 3)`, or `new SupportedVersionRange((short) 0, (short) -1)`.
Common situations: 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.
Related errors
- Cannot create a new partition reassignment without any…
- Empty string is not allowed.
- Invalid empty members has been provided
- Leading or trailing whitespace is not allowed.
- Null argument not allowed.
AI-assisted analysis of apache/kafka@996fb4585a (2026-08-11).
Data as JSON: /api/errors/1b7b4d99c5575aec.
Report an issue: GitHub.
Appendix: 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 996fb4585a)