oracle/graal · error · IllegalArgumentException
componentIndex must be non-negative: <componentIndex>
Error message
componentIndex must be non-negative: <componentIndex>
What it means
Version.getComponent(int componentIndex) validates its argument: a negative index throws IllegalArgumentException('componentIndex must be non-negative: <n>'). Indexes are 0-based over the version components (0 = major, 1 = minor, 2 = revision, ...); an index beyond the available components is legal and returns 0. Only negative values are rejected.
Source
Thrown at sdk/src/org.graalvm.home/src/org/graalvm/home/Version.java:362
* Version components are indexed as follows:
* <ul>
* <li>{@code componentIndex = 0} represents the major version</li>
* <li>{@code componentIndex = 1} represents the minor version</li>
* <li>{@code componentIndex = 2} represents the update version</li>
* </ul>
* If the specified {@code componentIndex} exceeds the number of available components, the
* method returns {@code 0}. For example, a version {@code 23.1} will return {@code 0} for
* {@code componentIndex = 2}.
* </p>
*
* @param componentIndex the index of the version component to retrieve; must be non-negative
* @throws IllegalArgumentException if {@code componentIndex} is negative
* @since 24.2
* @see Version#create(int...)
*/
public int getComponent(int componentIndex) {
if (componentIndex < 0) {
throw new IllegalArgumentException("componentIndex must be non-negative: " + componentIndex);
}
return componentIndex < versions.length ? versions[componentIndex] : 0;
}
/**
* Parses a GraalVM version from its String raw format. Throws {@link IllegalArgumentException}
* if the passed string is not a valid GraalVM version.
*
* @since 19.3
*/
public static Version parse(String versionString) throws IllegalArgumentException {
Objects.requireNonNull(versionString);
return new Version(versionString);
}
/**
* Constructs a new GraalVM version from a list of version numbers. The versions must not be
* <code>null</code> and none of the version numbers must be negative. At least one versionView on GitHub (pinned to a66e9ccd1d)
Solutions
- Clamp or validate the index before the call: if (i >= 0) v = version.getComponent(i).
- For 'last component' semantics, compute it from version.toString()/compareTo data, not negative indices.
- Validate externally supplied indices at the API boundary with a clear error message.
Example fix
// before
for (int i = n; i >= -1; i--) {
int comp = version.getComponent(i); // i == -1 -> throws
}
// after
for (int i = n; i >= 0; i--) {
int comp = version.getComponent(i);
} Defensive patterns
Strategy: validation
Validate before calling
static int component(Version v, int idx) {
return v.getComponent(Math.max(0, idx));
} Prevention
- Loop over components with i >= 0 conditions only.
- Validate user-supplied indices before calling getComponent.
- Remember: no negative-index 'from end' semantics here.
When it happens
Trigger: Calling version.getComponent(-1) directly, or getComponent(i) in a loop where i starts at -1 or is decremented past zero; passing a component index parsed from user input or config without validation.
Common situations: Reverse iteration over version components; 'find last non-zero component' loops that walk downward and overshoot; exposing version component indices in a CLI/config API where users type -1 meaning 'last' (java.util.List semantics do not apply here).
Related errors
- At least one non-zero version must be specified.
- Cannot compare {JavaLangRuntimeVersion.__name__} to {type(ot
- Invalid replay boolean flag
- Required replay field is null
- Unexpected architecture name ${archName}
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/733b44e9683a0663.
Report an issue: GitHub.