oracle/graal · error · IllegalArgumentException
illegal call to bits on
Error message
illegal call to bits on
What it means
JavaKind.getBitCount returns the bit width of a numeric kind (16 for Char/Short, 32 for Float/Int, 64 for Double/Long). Boolean, Void, Illegal, and Object are not in the switch, so calling getBitCount on them throws IllegalArgumentException 'illegal call to bits on <kind>'.
Source
Thrown at espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaKind.java:410
public int getBitCount() {
switch (this) {
case Boolean:
return 1;
case Byte:
return 8;
case Char:
case Short:
return 16;
case Float:
return 32;
case Int:
return 32;
case Double:
return 64;
case Long:
return 64;
default:
throw new IllegalArgumentException("illegal call to bits on " + this);
}
}
/**
* Returns the Espresso type (symbol) of this kind.
*
* @return the Espresso type (symbol) of this kind
*/
public Symbol<Type> getType() {
return type;
}
public Symbol<Name> getPrimitiveBinaryName() {
ErrorUtil.guarantee(isPrimitive(), "not a primitive");
return name;
}
public String getUnwrapMethodName() {View on GitHub (pinned to a66e9ccd1d)
Solutions
- Special-case Boolean (use getByteCount() == 1) and skip Object/Void/Illegal before calling getBitCount()
- Restrict calls to kind.isPrimitive() && kind != JavaKind.Void && kind != JavaKind.Boolean
Example fix
// before int bits = kind.getBitCount(); // fails for Boolean/Void/Object/Illegal // after int bits = (kind == JavaKind.Boolean) ? 1 : (kind.isPrimitive() && kind != JavaKind.Void) ? kind.getBitCount() : -1;
Defensive patterns
Strategy: type-guard
Validate before calling
if (!kind.isPrimitive() || kind == JavaKind.Void || kind == JavaKind.Boolean) throw new IllegalArgumentException("no bit count for " + kind); Type guard
static boolean hasBitCount(JavaKind k) { return k.isPrimitive() && k != JavaKind.Void && k != JavaKind.Boolean; } Prevention
- Remember Boolean is sized via getByteCount() (1 byte), not getBitCount()
- Use one shared guard for all numeric-kind accessors to avoid per-accessor drift
When it happens
Trigger: Calling getBitCount() on JavaKind.Boolean, Void, Illegal, or Object — e.g. generic sizing code computing slot widths or struct layouts over all kinds.
Common situations: Word/slot size computations that assume every kind has a bit width (Boolean is 1 byte but has no 'bits' entry here); table generation over JavaKind.values(); ports of Graal compiler code where the guard was lost.
Related errors
- illegal call to minValue on
- illegal call to maxValue 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/76d68137c01b5b38.
Report an issue: GitHub.