java-native-access/jna · error · IllegalArgumentException
Reading array of " + cls + " from memory not supported
Error message
Reading array of " + cls + " from memory not supported
What it means
Pointer.readArray (invoked from getValue for array types) encountered an array component type it cannot read from native memory. After handling byte/short/char/int/long/float/double/Pointer/Structure/NativeMapped arrays, any remaining element type is rejected with IllegalArgumentException.
Source
Thrown at src/com/sun/jna/Pointer.java:529
}
else {
sarray[i].useMemory(this, (int)(offset + i * sarray[i].size()), true);
sarray[i].read();
}
}
}
}
else if (NativeMapped.class.isAssignableFrom(cls)) {
NativeMapped[] array = (NativeMapped[])result;
NativeMappedConverter tc = NativeMappedConverter.getInstance(cls);
int size = Native.getNativeSize(result.getClass(), result) / array.length;
for (int i=0;i < array.length;i++) {
Object value = getValue(offset + size*i, tc.nativeType(), array[i]);
array[i] = (NativeMapped)tc.fromNative(value, new FromNativeContext(cls));
}
}
else {
throw new IllegalArgumentException("Reading array of "
+ cls
+ " from memory not supported");
}
}
/**
* Indirect the native pointer as a pointer to <code>byte</code>. This is
* equivalent to the expression
* <code>*((jbyte *)((char *)Pointer + offset))</code>.
*
* @param offset offset from pointer to perform the indirection
* @return the <code>byte</code> value being pointed to
*/
public byte getByte(long offset) {
return Native.getByte(this, this.peer, offset);
}
/**View on GitHub (pinned to d036ad9781)
Solutions
- Use a supported array component type: primitive arrays, Pointer[], Structure[], or NativeMapped implementations.
- Replace String[] structure fields with a single String (native char**) mapped via Pointer, or define a Structure describing the native layout.
- For custom element types, make the component class implement NativeMapped or extend Structure.
- Read the raw bytes/pointers yourself via pointer.getPointer/getByteArray and convert manually.
Example fix
// before String[] arr = (String[]) pointer.getValue(0, String[].class, new String[4]); // after Pointer[] ptrs = (Pointer[]) pointer.getValue(0, Pointer[].class, new Pointer[4]);
Defensive patterns
Strategy: validation
Validate before calling
static void requireSupportedArrayComponent(Class<?> component) {
boolean ok = component.isPrimitive()
|| Pointer.class.isAssignableFrom(component)
|| Structure.class.isAssignableFrom(component)
|| NativeMapped.class.isAssignableFrom(component);
if (!ok) throw new IllegalArgumentException("Unsupported array element type: " + component);
} Type guard
static boolean isReadableArray(Class<?> arrayType) {
Class<?> c = arrayType.getComponentType();
return c != null && (c.isPrimitive() || Pointer.class.isAssignableFrom(c)
|| Structure.class.isAssignableFrom(c) || NativeMapped.class.isAssignableFrom(c));
} Try / catch
try {
pointer.getValue(offset, array.getClass(), array);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Reading array of")) {
// read element-wise via supported types instead
} else throw e;
} Prevention
- Avoid String[], Object[], or interface-typed arrays in Structure definitions.
- Model native pointer arrays as Pointer[] and dereference individually.
- Make custom element types extend Structure or implement NativeMapped.
- Check component type support before calling getValue with an array type.
When it happens
Trigger: Calling pointer.getValue(offset, SomeArrayClass.class, arrayInstance) — or a Structure field read — where the array's component type is not a primitive, Pointer, Structure, or NativeMapped; e.g. an array of String[] elements or of arbitrary objects.
Common situations: Declaring a Structure field as String[] or Object[] expecting JNA to map it; reading arrays of custom POJOs that were never given a NativeMapped or Structure mapping; generics erasure leaving an unsupported component type.
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
- Writing array of " + cls + " to memory not supported
- Reading \"" + type + "\" from memory is not supported
- Writing " + type + " to memory is not supported
- No support for " + os
- Set sun.java2d.noddraw=true to enable transparent windows
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/d19dcb44b436e9f8.
Report an issue: GitHub.