{"record":{"id":"0531129b9cb07bce","repo":"java-native-access/jna","slug":"unknown-native-stack-allocation-size-for","errorCode":null,"errorMessage":"Unknown native stack allocation size for ","messagePattern":"Unknown native stack allocation size for ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/win32/StdCallFunctionMapper.java","lineNumber":57,"sourceCode":" * NOTE: if you use custom type mapping for primitive types, you may need to\n * override {@link #getArgumentNativeStackSize(Class)}.\n */\npublic class StdCallFunctionMapper implements FunctionMapper {\n    /** Override this to handle any custom class mappings.\n     * @param cls Java class of a parameter\n     * @return number of native bytes used for this class on the stack\n     */\n    protected int getArgumentNativeStackSize(Class<?> cls) {\n        if (NativeMapped.class.isAssignableFrom(cls)) {\n            cls = NativeMappedConverter.getInstance(cls).nativeType();\n        }\n        if (cls.isArray()) {\n            return Native.POINTER_SIZE;\n        }\n        try {\n            return Native.getNativeSize(cls);\n        } catch(IllegalArgumentException e) {\n            throw new IllegalArgumentException(\"Unknown native stack allocation size for \" + cls);\n        }\n    }\n\n    /**\n     * Convert the given Java method into a decorated {@code stdcall} name, if possible.\n     *\n     * @param library The {@link NativeLibrary} instance\n     * @param method The invoked {@link Method}\n     * @return The decorated name\n     */\n    @Override\n    public String getFunctionName(NativeLibrary library, Method method) {\n        String name = method.getName();\n        int pop = 0;\n        Class<?>[] argTypes = method.getParameterTypes();\n        for (Class<?> cls : argTypes) {\n            pop += getArgumentNativeStackSize(cls);\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/win32/StdCallFunctionMapper.java#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nint func(Object obj); // Object has no native size\n// after\nint func(Pointer p); // or a Structure/NativeMapped type","handlingStrategy":"validation","validationCode":"// Java, before registering the stdcall interface\nfor (Method m : Lib.class.getMethods())\n    for (Class<?> p : m.getParameterTypes()) {\n        try { com.sun.jna.Native.getNativeSize(p); }\n        catch (IllegalArgumentException e) { throw new IllegalStateException(m + \" param \" + p + \" has no native size\"); }\n    }","typeGuard":null,"tryCatchPattern":"try { mapper.getArgumentNativeStackSize(method, paramTypes, i); } catch (IllegalArgumentException e) { log.error(\"unmappable param \" + paramTypes[i]); }","preventionTips":["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"],"tags":["jna","stdcall","native-size","function-mapper"],"backgroundTag":"unsupported-operation","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}