{"record":{"id":"54864430f6b8b572","repo":"java-native-access/jna","slug":"function-name-may-not-be-null","errorCode":null,"errorMessage":"Function name may not be null","messagePattern":"Function name may not be null","errorType":"exception","errorClass":"java.lang.NullPointerException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/NativeLibrary.java","lineNumber":612,"sourceCode":"        return getFunction(functionName, callFlags, encoding);\n    }\n\n    /**\n     * Create a new  {@link Function} that is linked with a native\n     * function that follows a given calling flags.\n     *\n     * @param    functionName\n     *            Name of the native function to be linked with\n     * @param    callFlags\n     *            Flags affecting the function invocation\n     * @param   encoding\n     *                  Encoding to use to convert between Java and native\n     *                  strings.\n     * @throws   UnsatisfiedLinkError if the function is not found\n     */\n    public Function getFunction(String functionName, int callFlags, String encoding) {\n        if (functionName == null) {\n            throw new NullPointerException(\"Function name may not be null\");\n        }\n        synchronized (functions) {\n            String key = functionKey(functionName, callFlags, encoding);\n            Function function = functions.get(key);\n            if (function == null) {\n                function = new Function(this, functionName, callFlags, encoding);\n                functions.put(key, function);\n            }\n            return function;\n        }\n    }\n\n    /** @return this native library instance's options. */\n    public Map<String, ?> getOptions() {\n        return options;\n    }\n\n    /** Look up the given global variable within this library.","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/NativeLibrary.java#L594-L630","documentation":"Validation guard in NativeLibrary.getFunction: it fires because the caller passed a null function name when requesting a native function from the library. There is no default or fallback symbol, so a non-null name is mandatory before the native symbol lookup is attempted.","triggerScenarios":"Calling lib.getFunction(null) or getFunction(null, callFlags) / getFunction(null, callFlags, encoding), typically when the function name comes from an uninitialized variable or config value.","commonSituations":"Building bindings where symbol names are read from a table or properties file that is missing an entry; reflection-driven wrappers passing null names.","solutions":["Pass a non-null function name string","Check the source of the name (config, map lookup) and fail earlier with a clear message","If the symbol may not exist, use getFunction with a fallback or catch UnsatisfiedLinkError, not null"],"exampleFix":"// before\nFunction f = lib.getFunction(config.get(\"fn\"));\n// after\nString name = config.get(\"fn\");\nif (name == null) throw new IllegalArgumentException(\"Missing function name in config\");\nFunction f = lib.getFunction(name);","handlingStrategy":"validation","validationCode":"if (functionName == null || functionName.isEmpty()) {\n    throw new IllegalArgumentException(\"functionName required\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate symbol names loaded from config/maps before calling getFunction","Fail fast at configuration load time on missing names"],"tags":["jna","null-argument","function-lookup"],"backgroundTag":"null-argument","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}