{"record":{"id":"cffeee089feaf024","repo":"java-native-access/jna","slug":"jna-problems-loading-callback-ids-s","errorCode":null,"errorMessage":"JNA: Problems loading callback IDs: %s\n","messagePattern":"JNA: Problems loading callback IDs: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"native/dispatch.c","lineNumber":3368,"sourceCode":"JNI_OnLoad(JavaVM *jvm, void *UNUSED(reserved)) {\n  JNIEnv* env;\n  int result = JNI_VERSION_1_4;\n  int attached = (*jvm)->GetEnv(jvm, (void *)&env, JNI_VERSION_1_4) == JNI_OK;\n  const char* err;\n\n  if (!attached) {\n    if ((*jvm)->AttachCurrentThread(jvm, (void *)&env, NULL) != JNI_OK) {\n      fprintf(stderr, \"JNA: Can't attach native thread to VM on load\\n\");\n      return 0;\n    }\n  }\n\n  if ((err = JNA_init(env)) != NULL) {\n    fprintf(stderr, \"JNA: Problems loading core IDs: %s\\n\", err);\n    result = 0;\n  }\n  else if ((err = JNA_callback_init(env)) != NULL) {\n    fprintf(stderr, \"JNA: Problems loading callback IDs: %s\\n\", err);\n    result = 0;\n  }\n  if (!attached) {\n    if ((*jvm)->DetachCurrentThread(jvm) != 0) {\n      fprintf(stderr, \"JNA: could not detach thread on initial load\\n\");\n    }\n  }\n\n  return result;\n}\n\nJNIEXPORT void JNICALL\nJNI_OnUnload(JavaVM *vm, void *UNUSED(reserved)) {\n  jobject* refs[] = {\n    &classObject, &classClass, &classMethod,\n    &classString,\n#ifndef NO_NIO_BUFFERS\n    &classBuffer, &classByteBuffer, &classCharBuffer,","sourceCodeStart":3350,"sourceCodeEnd":3386,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/native/dispatch.c#L3350-L3386","documentation":"After core IDs initialize, JNA runs JNA_callback_init() to cache method IDs for callback dispatch (ffi_callback_invoke and related). If this step fails it returns an error string; JNA prints this message with the detail and marks native load as failed (result 0). Callback-based native interop will not function, even if non-callback JNA calls might partially work.","triggerScenarios":"JNA_callback_init cannot resolve the Callback class hierarchy or its ffi_callback_invoke method via JNI GetMethodID — typically due to a JNA jar/native-version mismatch, or com.sun.jna.Callback being invisible to the native lookup (classpath/module issues).","commonSituations":"Partially upgraded deployments where jna.jar was updated but the native library cached from an older version; shaded/uber jars that renamed or dropped com.sun.jna classes; security manager or classloader isolation hiding JNA internals.","solutions":["Clear cached native libraries and repack/redeploy with a single, consistent JNA version (jar and native dispatch from the same release).","Check the %s detail to see which callback ID failed to resolve and confirm that class/method exists in the shipped jna.jar.","If using shading/relocation, keep com.sun.jna unshaded or configure the shading plugin to preserve it.","Test with a minimal program (a single Callback registration) in a clean JVM to isolate classpath vs native-binary causes."],"exampleFix":"// before: uber-jar shaded com.sun.jna into com.myapp.shaded.jna\n<relocation><pattern>com.sun.jna</pattern><shadedPattern>com.myapp.shaded.jna</shadedPattern></relocation>\n// after: exclude JNA from relocation\n<relocation><pattern>com.sun.jna.internal.*</pattern> ... <!-- keep com.sun.jna untouched -->","handlingStrategy":"validation","validationCode":"// Smoke-test callback dispatch immediately after startup:\nCallback probe = () -> {};\nif (!callbackRegistry.add(probe)) {\n  throw new IllegalStateException(\"JNA callback dispatch not initialized correctly\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship jna.jar and its native dispatch library from the same release in one artifact.","Add a startup health check that registers and invokes a no-op callback.","Keep com.sun.jna off any shading/relocation rules."],"tags":["jni","jna","native","initialization","callbacks","version-mismatch"],"backgroundTag":"module-init-failed","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"}