{"record":{"id":"2985b5fe3c68e75c","repo":"java-native-access/jna","slug":"jna-extract-value-s","errorCode":null,"errorMessage":"JNA: extract_value: %s","messagePattern":"JNA: extract_value: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"native/dispatch.c","lineNumber":1638,"sourceCode":"  }\n  else if ((*env)->IsInstanceOf(env, value, classStructure)) {\n    void* ptr = getStructureAddress(env, value);\n    memcpy(buffer, ptr, size);\n  }\n  else if ((*env)->IsInstanceOf(env, value, classPointer)) {\n    *(void **)buffer = getNativeAddress(env, value);\n  }\n  else if ((*env)->IsInstanceOf(env, value, classString)) {\n    *(void **)buffer = newCStringEncoding(env, (jstring)value, encoding);\n  }\n  else if ((*env)->IsInstanceOf(env, value, classWString)) {\n    jstring s = (*env)->CallObjectMethod(env, value, MID_Object_toString);\n    *(void **)buffer = newWideCString(env, s);\n  }\n  else {\n    char msg[MSG_SIZE];\n    snprintf(msg, sizeof(msg), \"Can't convert type to native, native size %d\\n\", (int)size);\n    fprintf(stderr, \"JNA: extract_value: %s\", msg);\n    memset(buffer, 0, size);\n    throwByName(env, EError, msg);\n  }\n}\n\n/** Construct a new Java object from a native value.  */\njobject\nnew_object(JNIEnv* env, char jtype, void* valuep, jboolean promote, const char* encoding) {\n    switch(jtype) {\n    case 's':\n      return newJavaPointer(env, valuep);\n    case 'c':\n      return newJavaString(env, *(void**)valuep, encoding);\n    case 'w':\n      return newJavaString(env, *(void **)valuep, NULL);\n    case '*':\n      return newJavaPointer(env, *(void**)valuep);\n    case 'J':","sourceCodeStart":1620,"sourceCodeEnd":1656,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/native/dispatch.c#L1620-L1656","documentation":"In the native value-extraction routine, JNA converts a Java object argument to its native representation. When the Java type's native size is unknown the routine cannot convert it, prints this message with a detail string ('Can't convert type to native, native size N'), zeroes the output buffer, and throws a Java Lang/Error (throwByName) that the caller receives on the Java side.","triggerScenarios":"Passing a Java object as a native argument (or inside a Structure/callback argument) whose mapped native size JNA cannot determine — e.g. an unmapped custom object type, a wrong @Structure.FieldOrder type, or an argument type not covered by the ToNativeContext mapping.","commonSituations":"Declaring a Structure field or Library method parameter as a type JNA does not know how to map (custom class without a TypeMapper/Converter); version changes where an argument was Object-typed; typos in native signatures where a primitive got boxed incorrectly.","solutions":["Read the thrown Java Error's detail message ('Can't convert type to native, native size N') to find the offending argument type and native size.","Add a proper JNA mapping for the type: implement com.sun.jna.Callback, extend Structure, use IntegerType/Pointer, or register a TypeMapper/TypeConverter.","Fix the native signature declaration so the parameter type matches the C prototype (e.g. use Pointer or Memory instead of an arbitrary object).","Upgrade/downgrade JNA if the type used to map in a prior version; check the release notes for mapping changes."],"exampleFix":"// before: unmapped custom type as structure field\nclass Config { String name; }\nclass NativeConf extends Structure { public Config conf; }\n// after: map via supported types\nclass NativeConf extends Structure {\n  public byte[] conf; // or extend Structure / use TypeMapper\n  protected List<String> getFieldOrder() { return Collections.singletonList(\"conf\"); }\n}","handlingStrategy":"try-catch","validationCode":"// Before passing an object to native, ensure JNA can map it:\nif (!(arg instanceof Integer || arg instanceof Long || arg instanceof String\n      || arg instanceof Pointer || arg instanceof Structure || arg instanceof Callback)) {\n  throw new IllegalArgumentException(\"Type not natively mappable: \" + arg.getClass());\n}","typeGuard":"static boolean isNativelyMappable(Object o) {\n  return o == null || o instanceof Integer || o instanceof Long || o instanceof Short\n      || o instanceof Byte || o instanceof Character || o instanceof Float || o instanceof Double\n      || o instanceof Boolean || o instanceof String || o instanceof Pointer\n      || o instanceof Structure || o instanceof Callback;\n}","tryCatchPattern":"try {\n  nativeLib.call(arg);\n} catch (java.lang.Error e) { // JNA throws by name (Error family) from extract_value\n  if (String.valueOf(e.getMessage()).contains(\"Can't convert type to native\")) {\n    // fix mapping: wrap arg in Pointer/Structure or register a TypeConverter\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use only JNA-mappable types (primitives, String, Pointer, Structure, Callback, Buffer) in native signatures.","Register a TypeMapper for custom domain objects instead of passing them raw.","Keep native signature declarations synchronized with the C headers."],"tags":["jni","jna","native","type-mapping","arguments"],"backgroundTag":"type-mismatch","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"}