java-native-access/jna · critical · Error
Error looking up CallbackProxy.callback() method
Error message
Error looking up CallbackProxy.callback() method
What it means
This is a fatal java.lang.Error thrown in the static initializer of CallbackReference when reflection fails to look up CallbackProxy.callback(Object[]) — an internal JNA invariant that should never fail. It means the JNA jar on the classpath is corrupt, incomplete, or a mismatched mix of versions (e.g. the CallbackProxy class was altered, stripped by shading/proguard, or a stale class shadows the one from the jar). Because it is thrown from a static block, the first use of callbacks will fail with ExceptionInInitializerError wrapping this Error.
Source
Thrown at src/com/sun/jna/CallbackReference.java:72
// Access to callbackMap, directCallbackMap, pointerCallbackMap is protected
// by synchonizing on pointerCallbackMap
static final Map<Callback, CallbackReference> callbackMap = new WeakHashMap<>();
static final Map<Callback, CallbackReference> directCallbackMap = new WeakHashMap<>();
//callbacks with different signatures sharing the same pointer
static final Map<Pointer, Reference<Callback>[]> pointerCallbackMap = new WeakHashMap<>();
// Track memory allocations associated with this closure (usually String args)
static final Map<Object, Object> allocations =
Collections.synchronizedMap(new WeakHashMap<>());
// Global map of allocated closures to facilitate centralized cleanup
private static final Map<Long, Reference<CallbackReference>> allocatedMemory =
new ConcurrentHashMap<>();
private static final Method PROXY_CALLBACK_METHOD;
static {
try {
PROXY_CALLBACK_METHOD = CallbackProxy.class.getMethod("callback", new Class[] { Object[].class });
} catch(Exception e) {
throw new Error("Error looking up CallbackProxy.callback() method");
}
}
private static final Class<?> DLL_CALLBACK_CLASS;
static {
if (Platform.isWindows()) {
try {
DLL_CALLBACK_CLASS = Class.forName("com.sun.jna.win32.DLLCallback");
} catch(ClassNotFoundException e) {
throw new Error("Error loading DLLCallback class", e);
}
} else {
DLL_CALLBACK_CLASS = null;
}
}
private static final Map<Callback, CallbackThreadInitializer> initializers = new WeakHashMap<>();View on GitHub (pinned to d036ad9781)
Solutions
- Verify the JNA jar is intact: run 'unzip -t jna.jar' and confirm com/sun/jna/CallbackProxy.class exists with a callback(Object[]) method ('javap -p com.sun.jna.CallbackProxy').
- Replace the JNA jar with a clean release matching your version (download again; delete the stale copy in your build cache / app server lib).
- Check for duplicate/conflicting JNA classes on the classpath (old jna.jar in WEB-INF/lib, endorsed dirs, or application server shared lib) and remove all but one version.
- If using ProGuard/R8, add a keep rule for com.sun.jna.** (e.g. -keep class com.sun.jna.** { *; }).
Example fix
// before (stack trace)
java.lang.ExceptionInInitializerError
Caused by: java.lang.Error: Error looking up CallbackProxy.callback() method
// after
classpath contains exactly one intact jna.jar; ProGuard config:
-keep class com.sun.jna.** { *; } Defensive patterns
Strategy: validation
Validate before calling
// at app startup, before using callbacks
try {
Class.forName("com.sun.jna.CallbackProxy")
.getMethod("callback", Object[].class);
} catch (Throwable t) {
throw new IllegalStateException("Broken JNA installation: " + t, t);
} Try / catch
try { useCallbacks(); } catch (ExceptionInInitializerError e) { throw new IllegalStateException("JNA jar corrupt/incomplete: " + e.getCause(), e); } Prevention
- Ship exactly one intact JNA jar version per application.
- Add a startup smoke test that loads a trivial callback.
- Add ProGuard/R8 keep rules for com.sun.jna.** when shrinking.
- Verify jar integrity in CI (unzip -t) before deployment.
When it happens
Trigger: Any first use of a JNA Callback (e.g. passing a Callback to Native.loadLibrary/Library function invocation) triggers the CallbackReference static init; it throws if Class.getMethod("callback", Object[].class) on com.sun.jna.CallbackProxy throws for any reason (NoSuchMethodException, or any other Exception caught by the broad catch clause), typically because the CallbackProxy class resolution failed or the jar is corrupted/obfuscated.
Common situations: Shaded/fat jars where JNA classes were relocated or incompletely included; ProGuard/R8 stripping CallbackProxy.callback; mixing jna.jar of one version with classes of another on the classpath; broken jar download leaving a truncated com/sun/jna package.
Related errors
- Error loading DLLCallback class
- Failed to call addSuppressedMethod
- Callback method is inaccessible, make sure the interface is
- Can't create an instance of <klass>, requires a public no-ar
- There is an incompatible JNA native library installed on thi
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/e43ead5086cc22f7.
Report an issue: GitHub.