{"record":{"id":"10fc5136006c24e2","repo":"java-native-access/jna","slug":"jna-problems-loading-core-ids-s","errorCode":null,"errorMessage":"JNA: Problems loading core IDs: %s\n","messagePattern":"JNA: Problems loading core IDs: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"native/dispatch.c","lineNumber":3364,"sourceCode":"  return newJavaString(env, CHECKSUM, CHARSET_UTF8);\n}\n\nJNIEXPORT jint JNICALL\nJNI_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[] = {","sourceCodeStart":3346,"sourceCodeEnd":3382,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/native/dispatch.c#L3346-L3382","documentation":"During native library load, after obtaining a JNIEnv, JNA runs JNA_init() to cache core class/method/field IDs (Pointers, Memory, Structures, etc.). If JNA_init returns an error string, JNA prints this message with the detail, sets the load result to 0, and aborts initialization — every subsequent JNA native call will fail or misbehave because cached IDs are missing.","triggerScenarios":"JNA_init cannot find expected classes/methods via JNI FindNative/GetMethodID — e.g. a mixed JNA version install where the native dispatch library binary is from a different JNA release than jna.jar, or classes are missing from the boot/module path.","commonSituations":"Upgrading jna.jar without replacing the cached/extracted native dispatch library (stale jna dispatch .so/.dll in tmp or bundled); fat jars mixing JNA versions; module-path setups hiding com.sun.jna classes from JNI lookup.","solutions":["Delete stale extracted native libraries (e.g. os-arch temp dirs, jna.*.tmp) and restart so the native lib matches the jna.jar version.","Ensure a single consistent JNA version on the classpath (run mvn dependency:tree / gradle dependencies and exclude transitive older JNA).","If running under the module system, open/expose com.sun.jna packages so the native layer can resolve the classes.","Read the %s detail in the message — it names the exact missing ID — and align the bundled native dispatch binary with jna.jar."],"exampleFix":"// before: mixed versions\n// pom: jna 5.13.0 + transitive jna-platform 5.4.0 with old bundled dispatch\n// after: pin and exclude\n<dependency>\n  <groupId>net.java.dev.jna</groupId>\n  <artifactId>jna</artifactId>\n  <version>5.14.0</version>\n</dependency> <!-- exclude other jna artifacts transitively -->","handlingStrategy":"validation","validationCode":"// Verify a single consistent JNA version before load:\nString pkgVersion = com.sun.jna.Native.class.getPackage().getImplementationVersion();\nif (pkgVersion == null || !pkgVersion.equals(EXPECTED_JNA_VERSION)) {\n  throw new IllegalStateException(\"JNA version mismatch on classpath: \" + pkgVersion);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin exactly one JNA version and exclude transitive older JNA artifacts.","After upgrades, clear cached/extracted native dispatch binaries and redeploy.","Never shade or relocate com.sun.jna classes."],"tags":["jni","jna","native","initialization","version-mismatch","classpath"],"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"}