{"record":{"id":"e43ead5086cc22f7","repo":"java-native-access/jna","slug":"error-looking-up-callbackproxy-callback-method","errorCode":null,"errorMessage":"Error looking up CallbackProxy.callback() method","messagePattern":"Error looking up CallbackProxy\\.callback\\(\\) method","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/com/sun/jna/CallbackReference.java","lineNumber":72,"sourceCode":"    // Access to callbackMap, directCallbackMap, pointerCallbackMap is protected\n    // by synchonizing on pointerCallbackMap\n    static final Map<Callback, CallbackReference> callbackMap = new WeakHashMap<>();\n    static final Map<Callback, CallbackReference> directCallbackMap = new WeakHashMap<>();\n    //callbacks with different signatures sharing the same pointer\n    static final Map<Pointer, Reference<Callback>[]> pointerCallbackMap = new WeakHashMap<>();\n    // Track memory allocations associated with this closure (usually String args)\n    static final Map<Object, Object> allocations =\n            Collections.synchronizedMap(new WeakHashMap<>());\n    // Global map of allocated closures to facilitate centralized cleanup\n    private static final Map<Long, Reference<CallbackReference>> allocatedMemory =\n            new ConcurrentHashMap<>();\n    private static final Method PROXY_CALLBACK_METHOD;\n\n    static {\n        try {\n            PROXY_CALLBACK_METHOD = CallbackProxy.class.getMethod(\"callback\", new Class[] { Object[].class });\n        } catch(Exception e) {\n            throw new Error(\"Error looking up CallbackProxy.callback() method\");\n        }\n    }\n\n    private static final Class<?> DLL_CALLBACK_CLASS;\n\n    static {\n        if (Platform.isWindows()) {\n            try {\n                DLL_CALLBACK_CLASS = Class.forName(\"com.sun.jna.win32.DLLCallback\");\n            } catch(ClassNotFoundException e) {\n                throw new Error(\"Error loading DLLCallback class\", e);\n            }\n        } else {\n            DLL_CALLBACK_CLASS = null;\n        }\n    }\n\n    private static final Map<Callback, CallbackThreadInitializer> initializers = new WeakHashMap<>();","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/CallbackReference.java#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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.** { *; })."],"exampleFix":"// before (stack trace)\njava.lang.ExceptionInInitializerError\n  Caused by: java.lang.Error: Error looking up CallbackProxy.callback() method\n// after\nclasspath contains exactly one intact jna.jar; ProGuard config:\n-keep class com.sun.jna.** { *; }","handlingStrategy":"validation","validationCode":"// at app startup, before using callbacks\ntry {\n    Class.forName(\"com.sun.jna.CallbackProxy\")\n         .getMethod(\"callback\", Object[].class);\n} catch (Throwable t) {\n    throw new IllegalStateException(\"Broken JNA installation: \" + t, t);\n}","typeGuard":null,"tryCatchPattern":"try { useCallbacks(); } catch (ExceptionInInitializerError e) { throw new IllegalStateException(\"JNA jar corrupt/incomplete: \" + e.getCause(), e); }","preventionTips":["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."],"tags":["jna","classpath","static-initializer","reflection","corrupt-jar"],"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"}