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

  1. Convert to a supported array type: primitive array, Pointer[], String[], or Structure[]
  2. Use a Structure or Memory buffer to encode complex element types manually
  3. 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

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


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/aa0dd8b883c0b29b. Report an issue: GitHub.