oracle/graal · error · IllegalArgumentException
illegal call to maxValue on
Error message
illegal call to maxValue on
What it means
JavaKind.getMaxValue is the counterpart of getMinValue: it returns the maximum bit-pattern value for Boolean..Double only. Invoking it on Void, Illegal, or Object throws IllegalArgumentException 'illegal call to maxValue on <kind>'.
Source
Thrown at espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaKind.java:370
switch (this) {
case Boolean:
return 1;
case Byte:
return java.lang.Byte.MAX_VALUE;
case Char:
return java.lang.Character.MAX_VALUE;
case Short:
return java.lang.Short.MAX_VALUE;
case Int:
return java.lang.Integer.MAX_VALUE;
case Long:
return java.lang.Long.MAX_VALUE;
case Float:
return java.lang.Float.floatToRawIntBits(java.lang.Float.MAX_VALUE);
case Double:
return java.lang.Double.doubleToRawLongBits(java.lang.Double.MAX_VALUE);
default:
throw new IllegalArgumentException("illegal call to maxValue on " + this);
}
}
/**
* Number of bytes that are necessary to represent a value of this kind.
*
* @return the number of bytes
*/
public int getByteCount() {
if (this == Boolean) {
return 1;
} else {
return getBitCount() >> 3;
}
}
/**
* Number of bits that are necessary to represent a value of this kind.View on GitHub (pinned to a66e9ccd1d)
Solutions
- Filter non-numeric kinds first: only call getMaxValue() when kind.isPrimitive() && kind != JavaKind.Void
- Add an explicit default branch in your switch for Object/Void/Illegal instead of falling through
Example fix
// before
long max = kind.getMaxValue(); // crashes for Object/Void/Illegal
// after
if (kind.isPrimitive() && kind != JavaKind.Void) {
long max = kind.getMaxValue();
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!kind.isPrimitive() || kind == JavaKind.Void) throw new IllegalArgumentException("no maxValue for " + kind); Type guard
static boolean hasMinMax(JavaKind k) { return k.isPrimitive() && k != JavaKind.Void; } Prevention
- Guard all numeric JavaKind accessors with the same primitive-and-not-void predicate
- Keep Object/Void/Illegal branches explicit in switches over JavaKind
When it happens
Trigger: Calling kind.getMaxValue() on JavaKind.Object, JavaKind.Void, or JavaKind.Illegal, usually from generic range-analysis, interval, or test-harness code that walks every JavaKind constant.
Common situations: Range/bounds logic shared across all kinds; generated exhaustive switch over JavaKind.values(); refactoring code that previously only received primitive kinds.
Related errors
- illegal call to minValue on
- illegal call to bits on
- Expected value kind {} but got {}
- Bad argument kind at index {}: expected Boolean, got {}
- Bad argument kind at index {}: expected Byte, got {}
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/9c5559cf1b0b8bd7.
Report an issue: GitHub.