oracle/graal · error · IllegalArgumentException
Unsupported java version:
Error message
Unsupported java version:
What it means
JavaVersion.forVersion(int) normalizes a Java feature version number (e.g. 8, 21, 26; LATEST_SUPPORTED is 26). Any value below 1 — zero or negative — is rejected with IllegalArgumentException 'Unsupported java version: <n>'.
Source
Thrown at espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaVersion.java:90
public boolean contains(JavaVersion version) {
return version.inRange(low, high);
}
}
public static final JavaVersion HOST_VERSION = forVersion(Runtime.version());
public static final int LATEST_SUPPORTED = 26;
public static final int LATEST_SUPPORTED_CLASSFILE = ClassfileParser.JAVA_26_VERSION;
private final int version;
JavaVersion(int version) {
this.version = version;
}
public static JavaVersion forVersion(int version) {
if (version < 1) {
throw new IllegalArgumentException("Unsupported java version: " + version);
}
return new JavaVersion(version);
}
public static JavaVersion forVersion(String version) {
int begin = 0;
int end = version.length();
if (version.startsWith("1.")) {
begin = 2;
}
int firstDot = version.indexOf('.', begin);
if (firstDot >= 0) {
end = firstDot;
}
String normalizedVersion = version.substring(begin, end);
try {
int intVersion = Integer.parseInt(normalizedVersion);
return forVersion(intVersion);View on GitHub (pinned to a66e9ccd1d)
Solutions
- Validate the int (>= 1) before calling forVersion and surface your own configuration error naming the source of the bad value
- Trace where the 0/negative came from: usually a preceding parse failure left a default or sentinel
Example fix
// before
JavaVersion v = JavaVersion.forVersion(parsedVersion); // parsedVersion == 0 from failed parse
// after
if (parsedVersion < 1) throw new IllegalArgumentException("Bad version from config: " + raw);
JavaVersion v = JavaVersion.forVersion(parsedVersion); Defensive patterns
Strategy: validation
Validate before calling
if (version < 1) throw new IllegalArgumentException("version must be >= 1, got " + version); Prevention
- Never use 0/-1 as a sentinel version — use OptionalInt or an explicit error
- Assert parsed versions are within [1, JavaVersion.LATEST_SUPPORTED] in configuration code
When it happens
Trigger: Passing 0 or a negative int, often the result of a failed parse or an uninitialized field (0 default), or arithmetic like version - 1 underflowing.
Common situations: Parsing '-Djava.version' style strings when a custom parse already returned a sentinel 0/-1; an int field left at its default 0 before configuration; unit tests exercising edge values.
Related errors
- Unsupported java version: {} ({})
- Cannot compare {JavaLangRuntimeVersion.__name__} to {type(ot
- Out of scratch registers: %s
- No ClassConstant at constant pool index ${cpi}
- Authority component present
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/4dab4cb7863bbab5.
Report an issue: GitHub.