{"record":{"id":"1d510f57f8db7d3b","repo":"java-native-access/jna","slug":"unrecognized-calling-convention-convention","errorCode":null,"errorMessage":"Unrecognized calling convention: <convention>","messagePattern":"Unrecognized calling convention: <convention>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Function.java","lineNumber":292,"sourceCode":"    Function(Pointer functionAddress, int callFlags, String encoding) {\n        checkCallingConvention(callFlags & MASK_CC);\n        if (functionAddress == null\n            || functionAddress.peer == 0) {\n            throw new NullPointerException(\"Function address may not be null\");\n        }\n        this.functionName = functionAddress.toString();\n        this.callFlags = callFlags;\n        this.peer = functionAddress.peer;\n        this.options = Collections.EMPTY_MAP;\n        this.encoding = encoding != null\n            ? encoding : Native.getDefaultStringEncoding();\n    }\n\n    private void checkCallingConvention(int convention)\n        throws IllegalArgumentException {\n        // TODO: perform per-platform calling convention checks\n        if ((convention & MASK_CC) != convention) {\n            throw new IllegalArgumentException(\"Unrecognized calling convention: \"\n                                               + convention);\n        }\n    }\n\n    public String getName() {\n        return functionName;\n    }\n\n    public int getCallingConvention() {\n        return callFlags & MASK_CC;\n    }\n\n    /** Invoke the native function with the given arguments, returning the\n     * native result as an Object.\n     */\n    public Object invoke(Class<?> returnType, Object[] inArgs) {\n        return invoke(returnType, inArgs, this.options);\n    }","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Function.java#L274-L310","documentation":"JNA validates that the calling convention value fits within the allowed MASK_CC bits. Passing a convention value with bits outside the mask (or a convention the current build doesn't recognize) throws IllegalArgumentException. Per-platform validation is otherwise not performed.","triggerScenarios":"Passing Function.ALT_CONVENTION or a custom integer to a Function constructor or invoke() option where MASK_CC doesn't include that value; mixing conventions across platforms.","commonSituations":"Using stdcall (ALT_CONVENTION) on platforms where only CDECL is valid; hand-crafted convention constants copied from other libraries; typo'd option values.","solutions":["Use only the predefined constants Function.C_CONVENTION or Function.ALT_CONVENTION appropriate to your platform","Remove the CALLING_CONVENTION option/function argument so the platform default is used","Verify the platform supports the convention (ALT_CONVENTION is primarily Windows stdcall)"],"exampleFix":"// before\nnew Function(lib, \"f\", 0x7FFF); // bogus convention\n// after\nnew Function(lib, \"f\", Function.C_CONVENTION);","handlingStrategy":"validation","validationCode":"int cc = convention & Function.MASK_CC;\nif (cc != convention) throw new IllegalArgumentException(\"bad convention \" + convention);\nif (cc != Function.C_CONVENTION && cc != Function.ALT_CONVENTION) throw new IllegalArgumentException(\"unknown convention\");","typeGuard":null,"tryCatchPattern":"try {\n    f.invoke(method, types, ret, args, opts);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unrecognized calling convention\")) { /* fix option */ }\n}","preventionTips":["Only use Function.C_CONVENTION / Function.ALT_CONVENTION constants","Verify convention validity per target platform (stdcall is Windows-only) before enabling"],"tags":["jna","calling-convention","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}