{"record":{"id":"71f2fe648962ef31","repo":"java-native-access/jna","slug":"there-is-an-incompatible-jna-native-library-installed-on","errorCode":null,"errorMessage":"There is an incompatible JNA native library installed on this system\n\nExpected: <VERSION_NATIVE>\nFound: <nativeVersion> (<path>)\nTo resolve this issue you may do one of the following:\n - remove or uninstall the offending library","messagePattern":"There is an incompatible JNA native library installed on this system\n\nExpected: <VERSION_NATIVE>\nFound: <nativeVersion> \\(<path>\\)\nTo resolve this issue you may do one of the following:\n - remove or uninstall the offending library","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/com/sun/jna/Native.java","lineNumber":235,"sourceCode":"        int nativeMinor = Integer.parseInt(nativeVersionParts[1]);\n\n        if(expectedMajor != nativeMajor) {\n            return false;\n        }\n\n        if(expectedMinor > nativeMinor) {\n            return false;\n        }\n\n        return true;\n    }\n\n    static {\n        loadNativeDispatchLibrary();\n\n        if (! isCompatibleVersion(VERSION_NATIVE, getNativeVersion())) {\n            String LS = System.lineSeparator();\n            throw new Error(LS + LS\n                            + \"There is an incompatible JNA native library installed on this system\" + LS\n                            + \"Expected: \" + VERSION_NATIVE + LS\n                            + \"Found:    \" + getNativeVersion() + LS\n                            + (jnidispatchPath != null\n                               ? \"(at \" + jnidispatchPath + \")\" : System.getProperty(\"java.library.path\"))\n                            + \".\" + LS\n                            + \"To resolve this issue you may do one of the following:\" + LS\n                            + \" - remove or uninstall the offending library\" + LS\n                            + \" - set the system property jna.nosys=true\" + LS\n                            + \" - set jna.boot.library.path to include the path to the version of the \" + LS\n                            + \"   jnidispatch library included with the JNA jar file you are using\" + LS);\n        }\n\n        POINTER_SIZE = sizeof(TYPE_VOIDP);\n        LONG_SIZE = sizeof(TYPE_LONG);\n        WCHAR_SIZE = sizeof(TYPE_WCHAR_T);\n        SIZE_T_SIZE = sizeof(TYPE_SIZE_T);\n        BOOL_SIZE = sizeof(TYPE_BOOL);","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L217-L253","documentation":"In Native's static initializer, after loading the native dispatch library (jnidispatch), JNA compares the native library's reported version against the Java-side expected VERSION_NATIVE. A mismatch means the wrong jnidisplitch .so/.dll/.dylib is being loaded, so JNA throws a hard Error describing expected vs found versions and the library path.","triggerScenarios":"Class-initializing com.sun.jna.Native when an older/newer libjnidispatch.so (or jnidispatch.dll) from a different JNA release is found on java.library.path, bundled in the OS, or extracted from a stale jna.jar — getNativeVersion() != VERSION_NATIVE.","commonSituations":"Multiple JNA jars on the classpath (different versions in app and dependency tree); a system-installed JNA native library shadowing the bundled one; upgrading the Java JNA jar without updating the native library deployment; fat jars with stale extracted natives.","solutions":["Remove conflicting JNA jars so exactly one version is on the classpath (mvn dependency:tree / gradle dependencies to find duplicates).","Delete or update the stale native library found at the path printed in the error message.","Upgrade/downgrade the whole JNA dependency so Java and native versions match (e.g. all at 5.x.y).","Force the correct native library via jna.boot.library.path or by bundling the native lib inside jna.jar.","Set -Djna.nosys=true so JNA does not pick up system-installed copies."],"exampleFix":"// before (pom.xml): two versions\n<dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>4.5.1</version></dependency>\n// after: single matching version\n<dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>5.13.0</version></dependency>","handlingStrategy":"fallback","validationCode":"// before touching JNA, verify one consistent version is on the classpath\nClassLoader cl = Native.class.getClassLoader();\ntry (var stream = cl.getResources(\"com/sun/jna/Native.class\")) {\n    while (stream.hasMoreElements()) {\n        System.out.println(stream.nextElement()); // multiple URLs => version conflict\n    }\n}","typeGuard":"boolean jnaVersionConsistent() throws IOException {\n    var e = Native.class.getClassLoader().getResources(\"com/sun/jna/Native.class\");\n    int count = 0;\n    while (e.hasMoreElements()) { e.nextElement(); count++; }\n    return count == 1;\n}","tryCatchPattern":"try {\n    Class.forName(\"com.sun.jna.Native\", true, Native.class.getClassLoader());\n} catch (ExceptionInInitializerError e) {\n    throw new IllegalStateException(\n        \"JNA native/Java version mismatch: \" + e.getCause().getMessage()\n        + \" - fix classpath or remove stale libjnidispatch\", e);\n}","preventionTips":["Pin a single JNA version with a dependency-management BOM; run dependency conflict analysis in CI.","Never install libjnidispatch system-wide; let JNA extract its bundled native from the jar.","When upgrading jna.jar, upgrade the deployed native library in lockstep.","Set -Djna.nosys=true to prevent loading OS-installed JNA natives."],"tags":["jna","native-library","version-mismatch","classpath"],"backgroundTag":"missing-dependency","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"}