{"record":{"id":"3b2e4d1b899fb1ae","repo":"java-native-access/jna","slug":"jna-unhandled-result-conversion-d","errorCode":null,"errorMessage":"JNA: Unhandled result conversion: %d\n","messagePattern":"JNA: Unhandled result conversion: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"native/callback.c","lineNumber":531,"sourceCode":"      break;\n    case CVT_WSTRING: \n      *(void **)resp = getNativeString(env, *(void **)resp, JNI_TRUE);\n      break;\n    case CVT_STRUCTURE:\n      writeStructure(env, *(void **)resp);\n      *(void **)resp = getStructureAddress(env, *(void **)resp);\n      break;\n    case CVT_STRUCTURE_BYVAL:\n      writeStructure(env, *(void **)resp);\n      memcpy(oldresp, getStructureAddress(env, *(void **)resp), cb->cif.rtype->size);\n      break;\n    case CVT_CALLBACK: \n      *(void **)resp = getCallbackAddress(env, *(void **)resp);\n      break;\n    case CVT_DEFAULT:\n      break;\n    default:\n      fprintf(stderr, \"JNA: Unhandled result conversion: %d\\n\", cb->rflag);\n      break;\n    }\n    if (cb->conversion_flags) {\n      for (i=0;i < cif->nargs;i++) {\n        if (cb->conversion_flags[i] == CVT_STRUCTURE) {\n          writeStructure(env, *(void **)cbargs[i]);\n        }\n      }\n    }\n  }\n  else {\n    jobject result;\n    jobjectArray params =\n      (*env)->NewObjectArray(env, cif->nargs, classObject, NULL);\n    unsigned int i;\n\n    for (i=0;i < cif->nargs;i++) {\n      jobject arg = new_object(env, cb->arg_jtypes[i], cbargs[i], JNI_FALSE, cb->encoding);","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/native/callback.c#L513-L549","documentation":"In invoke_callback, JNA converts the native callback return value to a Java type based on a conversion flag (cb->rflag). If the flag is not one of the recognized CVT_* values, JNA prints this diagnostic to stderr and leaves the raw pointer in resp, meaning the Java callback will receive an incorrectly converted (or raw) return value. It indicates an internal inconsistency between the Java-side callback setup and the native conversion table.","triggerScenarios":"A Callback with a native-mapped return type whose resulting conversion flag (rflag) was never assigned a known CVT_* value during callback initialization; effectively any unmapped/unexpected return type reaching dispatch_callback.","commonSituations":"Custom or exotic return types in native-mapped callbacks, version skew between the JNA jar and its packed native library, or platform-specific return-type mappings not covered by the installed native build.","solutions":["Update JNA to the latest version so the jar and native library match.","Change the callback's Java return type to a type JNA explicitly supports (void, primitive, Pointer, Structure, String, etc.).","Inspect cb->rflag setup in callback.c/Java callback registration to find which type maps to the unknown flag value.","File a JNA bug with the printed rflag integer if the type should be supported."],"exampleFix":"// before\npublic int call() { ... } // exotic native-mapped mapping producing unknown rflag\n// after\npublic NativeLong call() { ... } // or another explicitly supported return type","handlingStrategy":"validation","validationCode":"// Java: before registering, confirm the callback's return type is JNA-supported\nClass<?> r = callback.getClass().getMethod(\"callback\").getReturnType();\nboolean ok = r == void.class || r.isPrimitive() || Pointer.class.isAssignableFrom(r)\n          || Structure.class.isAssignableFrom(r) || String.class == r;","typeGuard":"static boolean isSupportedReturnType(Class<?> t) {\n  return t == void.class || t.isPrimitive() || Number.class.isAssignableFrom(t)\n      || t == Boolean.class || t == Character.class || Pointer.class.isAssignableFrom(t)\n      || Structure.class.isAssignableFrom(t) || t == String.class;\n}","tryCatchPattern":null,"preventionTips":["Use only documented JNA-supported return types for Callback implementations","Keep the JNA jar and its bundled native library from the same release","Test every callback mapping on each target platform in CI","Watch stderr in tests so native diagnostics surface early"],"tags":["jni","native","callback","type-mapping"],"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"}