{"record":{"id":"ec09f879b32e9a94","repo":"java-native-access/jna","slug":"the-type-type-getname-is-not-supported-e-getmessage","errorCode":null,"errorMessage":"The type \"type.getName()\" is not supported: e.getMessage()","messagePattern":"The type \"type\\.getName\\(\\)\" is not supported: e\\.getMessage\\(\\)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":1475,"sourceCode":"    public static int getNativeSize(Class<?> type, Object value) {\n        if (type.isArray()) {\n            int len = Array.getLength(value);\n            if (len > 0) {\n                Object o = Array.get(value, 0);\n                return len * getNativeSize(type.getComponentType(), o);\n            }\n            // Don't process zero-length arrays\n            throw new IllegalArgumentException(\"Arrays of length zero not allowed: \" + type);\n        }\n        if (Structure.class.isAssignableFrom(type)\n            && !Structure.ByReference.class.isAssignableFrom(type)) {\n            return Structure.size((Class<Structure>) type, (Structure)value);\n        }\n        try {\n            return getNativeSize(type);\n        }\n        catch(IllegalArgumentException e) {\n            throw new IllegalArgumentException(\"The type \\\"\" + type.getName()\n                                               + \"\\\" is not supported: \"\n                                               + e.getMessage());\n        }\n    }\n\n    /**\n     * Returns the native size for a given Java class.  Structures are\n     * assumed to be <code>struct</code> pointers unless they implement\n     * {@link Structure.ByValue}.\n     *\n     * @param cls The Java class\n     * @return The native size for the class\n     */\n    public static int getNativeSize(Class<?> cls) {\n        if (NativeMapped.class.isAssignableFrom(cls)) {\n            cls = NativeMappedConverter.getInstance(cls).nativeType();\n        }\n        // boolean defaults to 32 bit integer if not otherwise mapped","sourceCodeStart":1457,"sourceCodeEnd":1493,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L1457-L1493","documentation":"Native.getNativeSize(type, value) first handles arrays and structures, then falls back to Native.getNativeSize(type) for the scalar cases it knows (primitives, pointers, etc.). If that fallback throws IllegalArgumentException, the type is simply not a supported JNA native argument type, and the error is rethrown naming the offending class and the underlying reason.","triggerScenarios":"Passing a Java type JNA cannot map to native — arbitrary POJOs, boxed types in unsupported positions, generic types, interfaces other than JNA's recognized ones — to Native.getNativeSize or as a mapped function/structure-field type.","commonSituations":"Accidentally mapping a struct field or callback parameter with a custom object type instead of a JNA Structure/IntegerType/pointer, or refactoring a mapped interface after which a previously-primitive parameter became an unsupported type.","solutions":["Map custom data to a JNA-supported type: subclass Structure for C structs, IntegerType for C ints/enums, or use Pointer/ByReference.","Read e.getMessage() in the error — it names the underlying reason from the inner getNativeSize call and usually points at the exact unsupported mapping.","Replace generic Object/POJO parameters in the library interface with primitives, String/WString, arrays, Buffer, Callback, or Structure types.","For opaque native handles, use com.sun.jna.PointerType or Memory instead of a plain Java class."],"exampleFix":"// before\nclass Config { int flags; } // POJO used as native arg\nint query(Config cfg);\n\n// after\nclass Config extends Structure {\n    public int flags;\n    @Override protected List<String> getFieldOrder() { return Arrays.asList(\"flags\"); }\n}\nint query(Config cfg);","handlingStrategy":"type-guard","validationCode":"static void requireMappable(Class<?> t) {\n    if (!(t.isPrimitive() || Number.class.isAssignableFrom(t) || Structure.class.isAssignableFrom(t)\n          || Pointer.class.isAssignableFrom(t) || String.class == t || WString.class == t\n          || t.isArray() || Callback.class.isAssignableFrom(t))) {\n        throw new IllegalArgumentException(\"Type not JNA-mappable: \" + t);\n    }\n}","typeGuard":"static boolean isJnaMappable(Class<?> t) {\n    return t.isPrimitive() || Structure.class.isAssignableFrom(t)\n        || PointerType.class.isAssignableFrom(t) || Callback.class.isAssignableFrom(t)\n        || String.class == t || WString.class == t || t.isArray();\n}","tryCatchPattern":"try {\n    int size = Native.getNativeSize(type, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is not supported\")) {\n        throw new IllegalStateException(\"Change mapping for \" + type + \" to a Structure/IntegerType/Pointer\", e);\n    } else { throw e; }\n}","preventionTips":["Review every mapped interface signature: only primitives, JNA types, Structures, arrays, Buffers, Callbacks, and String/WString belong there.","Model C structs as Structure subclasses and C enums as IntegerType subclasses from day one.","Run interface mapping early in CI so unsupported types surface before runtime use.","Read the nested message — it names the exact unsupported sub-mapping."],"tags":["jna","type-mapping","unsupported-type","native-size"],"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"}