{"record":{"id":"23009b1d02e62e2f","repo":"java-native-access/jna","slug":"type-is-not-a-supported-argument-type-in-method-method","errorCode":null,"errorMessage":"type is not a supported argument type (in method method.getName() in cls)","messagePattern":"type is not a supported argument type \\(in method method\\.getName\\(\\) in cls\\)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":1957,"sourceCode":"                case CVT_STRUCTURE:\n                case CVT_OBJECT:\n                    closure_rtype = rtype = FFIType.get(Pointer.class).getPointer().peer;\n                    break;\n                case CVT_STRUCTURE_BYVAL:\n                    closure_rtype = FFIType.get(Pointer.class).getPointer().peer;\n                    rtype = FFIType.get(rclass).getPointer().peer;\n                    break;\n                default:\n                    closure_rtype = rtype = FFIType.get(rclass).getPointer().peer;\n            }\n\n            for (int t=0;t < ptypes.length;t++) {\n                Class<?> type = ptypes[t];\n                sig += getSignature(type);\n                int conversionType = getConversion(type, mapper, allowObjects);\n                cvt[t] = conversionType;\n                if (conversionType == CVT_UNSUPPORTED) {\n                    throw new IllegalArgumentException(type + \" is not a supported argument type (in method \" + method.getName() + \" in \" + cls + \")\");\n                }\n                if ((conversionType == CVT_NATIVE_MAPPED)\n                    || (conversionType == CVT_NATIVE_MAPPED_STRING)\n                    || (conversionType == CVT_NATIVE_MAPPED_WSTRING)\n                    || (conversionType == CVT_INTEGER_TYPE)) {\n                    type = NativeMappedConverter.getInstance(type).nativeType();\n                } else if ((conversionType == CVT_TYPE_MAPPER)\n                        || (conversionType == CVT_TYPE_MAPPER_STRING)\n                        || (conversionType == CVT_TYPE_MAPPER_WSTRING)) {\n                    toNative[t] = mapper.getToNativeConverter(type);\n                }\n\n                // Determine the type that will be passed to the native\n                // function, as well as the type to be passed\n                // from Java initially\n                switch(conversionType) {\n                    case CVT_STRUCTURE_BYVAL:\n                    case CVT_INTEGER_TYPE:","sourceCodeStart":1939,"sourceCodeEnd":1975,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L1939-L1975","documentation":"JNA throws this IllegalArgumentException when a native method's parameter type cannot be mapped to a native argument type. During interface registration each parameter is checked with getConversion(); CVT_UNSUPPORTED aborts with the method and class named. This is a setup-time failure, not a call-time one.","triggerScenarios":"Loading or registering a Library interface where any method parameter is of a type JNA cannot convert (e.g. java.io.File, arbitrary POJO, multi-dimensional arrays, autoboxed collections).","commonSituations":"Writing bindings with signatures like void write(File f) or void process(MyDto dto) without a TypeMapper; migrating code that assumed reflection-based serialization; forgetting a NativeMappedConverter for a custom type.","solutions":["Replace the unsupported parameter type with a supported one (int, long, Pointer, Structure, String, byte[]/Buffer, Callback, etc.).","Implement a ToNativeConverter for the class and supply it via a DefaultTypeMapper in the load() options.","Extend NativeMapped/IntegerType for the argument class so JNA can map it natively.","Pass the data through Pointer/Structure explicitly instead of Java objects."],"exampleFix":"// before\nint open(File path, int flags); // File unsupported\n// after\nint open(String path, int flags);","handlingStrategy":"validation","validationCode":"for (Method m : MyLib.class.getMethods()) {\n    for (Class<?> p : m.getParameterTypes()) {\n        boolean ok = p.isPrimitive() || p == String.class\n            || Pointer.class.isAssignableFrom(p) || Structure.class.isAssignableFrom(p)\n            || p.isArray() || Buffer.class.isAssignableFrom(p)\n            || Callback.class.isAssignableFrom(p);\n        if (!ok) throw new IllegalStateException(\n            \"Unsupported argument type \" + p + \" in \" + m);\n    }\n}","typeGuard":"boolean isSupportedArg(Class<?> p) {\n    return p.isPrimitive() || p == String.class || p.isArray()\n        || Buffer.class.isAssignableFrom(p)\n        || Pointer.class.isAssignableFrom(p)\n        || Structure.class.isAssignableFrom(p)\n        || Callback.class.isAssignableFrom(p);\n}","tryCatchPattern":"try {\n    lib = Native.load(\"mylib\", MyLib.class);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is not a supported argument type\")) {\n        throw new ConfigurationException(\"Unsupported parameter type: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Keep parameter types within the supported set; pass complex data as Pointer/Structure.","Register a TypeMapper for custom value classes before load().","Load the library in a unit test to catch signature mistakes early."],"tags":["jna","unsupported-type","argument-type","native-binding"],"backgroundTag":"unsupported-operation","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"}