java-native-access/jna · error · IllegalArgumentException
Unsupported array argument type: <componentType>
Error message
Unsupported array argument type: <componentType>
What it means
When an argument is a Java array whose component type is not one of the array types JNA can marshal (primitive arrays, Pointer arrays, String arrays, Structure arrays, etc.), JNA throws IllegalArgumentException naming the unsupported component type.
Source
Thrown at src/com/sun/jna/Function.java:624
}
if (byRef) {
Structure.autoWrite(ss);
Pointer[] pointers = new Pointer[ss.length + 1];
for (int i=0;i < ss.length;i++) {
pointers[i] = ss[i] != null ? ss[i].getPointer() : null;
}
return new PointerArray(pointers);
} else if (ss.length == 0) {
throw new IllegalArgumentException("Structure array must have non-zero length");
} else if (ss[0] == null) {
Structure.newInstance((Class<? extends Structure>) type).toArray(ss);
return ss[0].getPointer();
} else {
Structure.autoWrite(ss);
return ss[0].getPointer();
}
} else if (argClass.isArray()){
throw new IllegalArgumentException("Unsupported array argument type: "
+ argClass.getComponentType());
} else if (allowObjects) {
return arg;
} else if (!Native.isSupportedNativeType(arg.getClass())) {
throw new IllegalArgumentException("Unsupported argument type "
+ arg.getClass().getName()
+ " at parameter " + index
+ " of function " + getName());
}
return arg;
}
private boolean isPrimitiveArray(Class<?> argClass) {
return argClass.isArray()
&& argClass.getComponentType().isPrimitive();
}
/**View on GitHub (pinned to d036ad9781)
Solutions
- Convert to a supported array type: primitive array, Pointer[], String[], or Structure[]
- Use a Structure or Memory buffer to encode complex element types manually
- Register a TypeMapper/converter for the element type via library options
Example fix
// before
f(new Integer[]{1,2,3});
// after
f(new int[]{1,2,3}); Defensive patterns
Strategy: validation
Validate before calling
Class<?> c = arg.getClass();
if (c.isArray() && !c.getComponentType().isPrimitive()
&& c.getComponentType() != Pointer.class
&& c.getComponentType() != String.class
&& !Structure.class.isAssignableFrom(c.getComponentType())) {
throw new IllegalStateException("unsupported array type " + c.getComponentType());
} Prevention
- Use primitive arrays, Pointer[], String[], or Structure[] only for native array arguments
- Convert boxed arrays (Integer[], Double[]) to primitive arrays before native calls
- Register a TypeMapper for custom element types instead of passing raw object arrays
When it happens
Trigger: Passing e.g. Object[], List[], or arrays of arbitrary POJOs as arguments to a native function invocation.
Common situations: Passing boxed arrays like Integer[] instead of int[]; passing arrays of enums or custom objects without a Structure/TypeMapper conversion; generated bindings leaking Java-only array types.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The given priority value is invalid!
- must be set from byte[]
- Unrecognized calling convention: <convention>
- Unsupported return type <returnType> in function <name>
- Function <name> declared Structure[] at parameter <index> bu
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/aa0dd8b883c0b29b.
Report an issue: GitHub.