java-native-access/jna · critical · Error
There is an incompatible JNA native library installed on thi
Error message
There is an incompatible JNA native library installed on this system Expected: <VERSION_NATIVE> Found: <nativeVersion> (<path>) To resolve this issue you may do one of the following: - remove or uninstall the offending library
What it means
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.
Source
Thrown at src/com/sun/jna/Native.java:235
int nativeMinor = Integer.parseInt(nativeVersionParts[1]);
if(expectedMajor != nativeMajor) {
return false;
}
if(expectedMinor > nativeMinor) {
return false;
}
return true;
}
static {
loadNativeDispatchLibrary();
if (! isCompatibleVersion(VERSION_NATIVE, getNativeVersion())) {
String LS = System.lineSeparator();
throw new Error(LS + LS
+ "There is an incompatible JNA native library installed on this system" + LS
+ "Expected: " + VERSION_NATIVE + LS
+ "Found: " + getNativeVersion() + LS
+ (jnidispatchPath != null
? "(at " + jnidispatchPath + ")" : System.getProperty("java.library.path"))
+ "." + LS
+ "To resolve this issue you may do one of the following:" + LS
+ " - remove or uninstall the offending library" + LS
+ " - set the system property jna.nosys=true" + LS
+ " - set jna.boot.library.path to include the path to the version of the " + LS
+ " jnidispatch library included with the JNA jar file you are using" + LS);
}
POINTER_SIZE = sizeof(TYPE_VOIDP);
LONG_SIZE = sizeof(TYPE_LONG);
WCHAR_SIZE = sizeof(TYPE_WCHAR_T);
SIZE_T_SIZE = sizeof(TYPE_SIZE_T);
BOOL_SIZE = sizeof(TYPE_BOOL);View on GitHub (pinned to d036ad9781)
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.
Example fix
// before (pom.xml): two versions <dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>4.5.1</version></dependency> // after: single matching version <dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>5.13.0</version></dependency>
Defensive patterns
Strategy: fallback
Validate before calling
// before touching JNA, verify one consistent version is on the classpath
ClassLoader cl = Native.class.getClassLoader();
try (var stream = cl.getResources("com/sun/jna/Native.class")) {
while (stream.hasMoreElements()) {
System.out.println(stream.nextElement()); // multiple URLs => version conflict
}
} Type guard
boolean jnaVersionConsistent() throws IOException {
var e = Native.class.getClassLoader().getResources("com/sun/jna/Native.class");
int count = 0;
while (e.hasMoreElements()) { e.nextElement(); count++; }
return count == 1;
} Try / catch
try {
Class.forName("com.sun.jna.Native", true, Native.class.getClassLoader());
} catch (ExceptionInInitializerError e) {
throw new IllegalStateException(
"JNA native/Java version mismatch: " + e.getCause().getMessage()
+ " - fix classpath or remove stale libjnidispatch", e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- JNA: Problems loading core IDs: %s
- Error looking up CallbackProxy.callback() method
- Error loading DLLCallback class
- Invalid library name "<libname>"
- <libname> does not implement an interface: <interfaceClassNa
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/71f2fe648962ef31.
Report an issue: GitHub.