java-native-access/jna · error · java.lang.IllegalArgumentException
Unknown native stack allocation size for
Error message
Unknown native stack allocation size for
What it means
StdCallFunctionMapper.getArgumentNativeStackSize rethrows IllegalArgumentException when Native.getNativeSize(cls) cannot determine the native size of a method parameter type. This mapper decorates stdcall function names with the total stack size of arguments, so every parameter must have a known native size.
Solutions
- Change unsupported parameter types to JNA-mappable ones (Pointer, int, NativeLong, Structure, Callback, String/WString).
- If a custom type is intended, make it extend Structure or implement NativeMapped so getNativeSize can compute its size.
- Inspect the exception's cause (Native.getNativeSize) to identify which parameter class is unmappable.
Example fix
// before int func(Object obj); // Object has no native size // after int func(Pointer p); // or a Structure/NativeMapped type
Defensive patterns
Strategy: validation
Validate before calling
// Java, before registering the stdcall interface
for (Method m : Lib.class.getMethods())
for (Class<?> p : m.getParameterTypes()) {
try { com.sun.jna.Native.getNativeSize(p); }
catch (IllegalArgumentException e) { throw new IllegalStateException(m + " param " + p + " has no native size"); }
} Try / catch
try { mapper.getArgumentNativeStackSize(method, paramTypes, i); } catch (IllegalArgumentException e) { log.error("unmappable param " + paramTypes[i]); } Prevention
- Use only JNA-mappable parameter types (primitives, Pointer, Structure, NativeMapped, String)
- Validate library interface signatures at startup with Native.getNativeSize
- Keep custom NativeMapped implementations providing proper nativeSize
When it happens
Trigger: Mapping an interface method whose parameter type has no native size — e.g. a non-mappable Java class, a String used where a pointer type is expected, an unmapped object, or a Structure without proper field mapping.
Common situations: Defining a stdcall callback/library interface with raw Object, boxed types, or unannotated custom classes as parameters; JNA version changes making a type previously sizeable now unsupported.
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
- Arrays of length zero not allowed: type
- Invalid Structure field in " + getClass() + ", field name…
- Native size for type "cls.getName()" is unknown
- Nested Structure arrays must use a derived Structure type…
- The type "type.getName()" is not supported: e.getMessage()
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/0531129b9cb07bce.
Report an issue: GitHub.
Appendix: source
Thrown at src/com/sun/jna/win32/StdCallFunctionMapper.java:57
* NOTE: if you use custom type mapping for primitive types, you may need to
* override {@link #getArgumentNativeStackSize(Class)}.
*/
public class StdCallFunctionMapper implements FunctionMapper {
/** Override this to handle any custom class mappings.
* @param cls Java class of a parameter
* @return number of native bytes used for this class on the stack
*/
protected int getArgumentNativeStackSize(Class<?> cls) {
if (NativeMapped.class.isAssignableFrom(cls)) {
cls = NativeMappedConverter.getInstance(cls).nativeType();
}
if (cls.isArray()) {
return Native.POINTER_SIZE;
}
try {
return Native.getNativeSize(cls);
} catch(IllegalArgumentException e) {
throw new IllegalArgumentException("Unknown native stack allocation size for " + cls);
}
}
/**
* Convert the given Java method into a decorated {@code stdcall} name, if possible.
*
* @param library The {@link NativeLibrary} instance
* @param method The invoked {@link Method}
* @return The decorated name
*/
@Override
public String getFunctionName(NativeLibrary library, Method method) {
String name = method.getName();
int pop = 0;
Class<?>[] argTypes = method.getParameterTypes();
for (Class<?> cls : argTypes) {
pop += getArgumentNativeStackSize(cls);
}View on GitHub (pinned to d036ad9781)