java-native-access/jna · error · java.lang.IllegalArgumentException
Class type <paramTypes[i].getName()> not mapped to primitive
Error message
Class type <paramTypes[i].getName()> not mapped to primitive default value.
What it means
CallbackProxy builds a parameters array of default primitive values for the reflected event method; the chain of equals(...) checks only covers known primitives (boolean, int, long, float, double, etc.). If a parameter type is not in the map it throws this IllegalArgumentException. It indicates the callback method signature uses a type the proxy's default-value table does not handle.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/COM/util/CallbackProxy.java:230
// exception occurs while doing the call into the target method
for (int i = 0; i < params.length; i++) {
if (params[i] == null && paramTypes[i].isPrimitive()) {
if (paramTypes[i].equals(boolean.class)) {
params[i] = DEFAULT_BOOLEAN;
} else if (paramTypes[i].equals(byte.class)) {
params[i] = DEFAULT_BYTE;
} else if (paramTypes[i].equals(short.class)) {
params[i] = DEFAULT_SHORT;
} else if (paramTypes[i].equals(int.class)) {
params[i] = DEFAULT_INT;
} else if (paramTypes[i].equals(long.class)) {
params[i] = DEFAULT_LONG;
} else if (paramTypes[i].equals(float.class)) {
params[i] = DEFAULT_FLOAT;
} else if (paramTypes[i].equals(double.class)) {
params[i] = DEFAULT_DOUBLE;
} else {
throw new IllegalArgumentException("Class type " + paramTypes[i].getName() + " not mapped to primitive default value.");
}
}
}
try {
eventMethod.invoke(comEventCallbackListener, params);
} catch (Exception e) {
List<String> decodedClassNames = new ArrayList<>(params.length);
for (Object o : params) {
if (o == null) {
decodedClassNames.add("NULL");
} else {
decodedClassNames.add(o.getClass().getName());
}
}
CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent(
"Exception invoking method " + eventMethod + " supplied: " + decodedClassNames.toString(), e);
}View on GitHub (pinned to d036ad9781)
Solutions
- Change the callback method's parameter types to ones the proxy supports (matching the real event signature)
- Check CallbackProxy.invokeOnThread for the exact list of supported primitive types in your JNA version
- If you need the real values rather than defaults, ensure the dispId-to-Method mapping matches so actual VARIANT args are converted instead of defaults being filled
- Upgrade/patch JNA if your primitive type should be supported by a newer version
Example fix
// before void onProgress(char stage); // after void onProgress(int stage);
Defensive patterns
Strategy: try-catch
Validate before calling
for (Class<?> p : callbackMethod.getParameterTypes()) {
if (!p.isPrimitive() && p != String.class && !DISPATCHED_TYPES.contains(p))
throw new IllegalArgumentException("unsupported callback param: " + p);
} Try / catch
try { listenerMethod.invoke(target, args); } catch (IllegalArgumentException e) { if (e.getMessage().contains("not mapped to primitive default value")) { log.error("fix callback signature: " + e.getMessage()); } } Prevention
- Match callback method signatures exactly to the COM event signature
- Use plain primitives (int, long, double, boolean, float) in event callbacks
- Keep callbacks in sync with the type library
When it happens
Trigger: Defining an IComEventCallbackListener method whose parameters include an unmapped type (e.g. char, byte, or an object type) so CallbackProxy.invokeOnThread cannot synthesize default values for a discarded event call.
Common situations: Writing an event callback signature that does not match the actual COM dispinterface signature; using wrapper types (Integer, String[]) or custom objects where the proxy expects primitives; JNA version changes adding/removing supported primitive mappings.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- advise: Interface must define a value for either iid via the
- fieldName must be a public field of type resultClass.getName
- remove
- Output directory NOT sucessfully created to: <comRootDir>
- Commandline parameter not found: <key>
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/1462b0c62299fc37.
Report an issue: GitHub.