{"record":{"id":"86a27c8908aefa97","repo":"java-native-access/jna","slug":"unsupported-argument-type-argclassname-at-parameter-index-of","errorCode":null,"errorMessage":"Unsupported argument type <argClassName> at parameter <index> of function <name>","messagePattern":"Unsupported argument type <argClassName> at parameter <index> of function <name>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Function.java","lineNumber":629,"sourceCode":"                    pointers[i] = ss[i] != null ? ss[i].getPointer() : null;\n                }\n                return new PointerArray(pointers);\n            } else if (ss.length == 0) {\n                throw new IllegalArgumentException(\"Structure array must have non-zero length\");\n            } else if (ss[0] == null) {\n                Structure.newInstance((Class<? extends Structure>) type).toArray(ss);\n                return ss[0].getPointer();\n            } else {\n                Structure.autoWrite(ss);\n                return ss[0].getPointer();\n            }\n        } else if (argClass.isArray()){\n            throw new IllegalArgumentException(\"Unsupported array argument type: \"\n                                               + argClass.getComponentType());\n        } else if (allowObjects) {\n            return arg;\n        } else if (!Native.isSupportedNativeType(arg.getClass())) {\n            throw new IllegalArgumentException(\"Unsupported argument type \"\n                                               + arg.getClass().getName()\n                                               + \" at parameter \" + index\n                                               + \" of function \" + getName());\n        }\n        return arg;\n    }\n\n    private boolean isPrimitiveArray(Class<?> argClass) {\n        return argClass.isArray()\n            && argClass.getComponentType().isPrimitive();\n    }\n\n    /**\n     * Call the native function being represented by this object\n     *\n     * @param args Arguments to pass to the native function\n     */\n    public void invoke(Object[] args) {","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Function.java#L611-L647","documentation":"JNA throws this IllegalArgumentException in Function.convertArgument when an argument passed to a native function call is of a Java type that JNA cannot map to a native type (and is not an array case or an allowed plain Object). JNA only supports a fixed set of mappings (primitives, Pointer, Structure, Callback, String, WString, Buffer, IntegerType, etc.).","triggerScenarios":"Calling a method on a Library interface (via Function.invoke -> convertArgument) with a parameter of an unmapped type, e.g. a POJO, BigDecimal, List, or custom class not extending PointerType/IntegerType and not a Structure/Callback.","commonSituations":"Passing Java collection or wrapper objects as native arguments; passing a String where a Structure is required; using java.lang.Object parameters without W32APIOptions/allowObjects; refactoring an interface signature to a non-mappable type after a JNA upgrade.","solutions":["Change the parameter type to a JNA-mappable type (String, Pointer, Structure, Callback, IntegerType, primitive, array of those).","Wrap the object: subclass PointerType or Structure and pass that.","For Windows WString APIs, ensure appropriate options so String maps correctly; otherwise convert explicitly.","If you truly need pass-through, use Pointer or pass the object through a Structure field of type Pointer."],"exampleFix":"// before\nint process(Object obj);\n// after\nint process(MyStruct struct); // MyStruct extends Structure","handlingStrategy":"type-guard","validationCode":"static boolean isJnaMappable(Object o) {\n  return o == null || o instanceof Boolean || o instanceof Byte || o instanceof Short\n      || o instanceof Character || o instanceof Integer || o instanceof Long || o instanceof Float\n      || o instanceof Double || o instanceof String || o instanceof WString || o instanceof Buffer\n      || o instanceof Pointer || o instanceof Structure || o instanceof Callback\n      || (o != null && o.getClass().isArray());\n}","typeGuard":"static <T> T requireMappable(T arg) {\n  if (!isJnaMappable(arg)) throw new IllegalArgumentException(\"Not JNA-mappable: \" + arg.getClass());\n  return arg;\n}","tryCatchPattern":"try {\n  lib.fn(arg);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unsupported argument type\")) {\n    throw new IllegalStateException(\"Convert arg to Pointer/Structure/String before native call\", e);\n  }\n  throw e;\n}","preventionTips":["Map only primitives, String, Pointer, Structure, Callback, IntegerType and arrays of those in Library interfaces.","Wrap custom data in Structure or PointerType subclasses.","Review interface signatures after JNA upgrades.","Add unit tests invoking each mapped method with valid args."],"tags":["jna","native-binding","argument-type","type-mapping"],"backgroundTag":"unsupported-argument-type","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}