{"record":{"id":"942c7a718c38ad0d","repo":"java-native-access/jna","slug":"invalid-library-name-libname","errorCode":null,"errorMessage":"Invalid library name \"<libname>\"","messagePattern":"Invalid library name \"<libname>\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Library.java","lineNumber":179,"sourceCode":"                this.handler = handler;\n                this.function = function;\n                this.isVarArgs = isVarArgs;\n                this.options = options;\n                this.parameterTypes = parameterTypes;\n                this.methodHandle = null;\n            }\n        }\n\n        private final NativeLibrary nativeLibrary;\n        private final Class<?> interfaceClass;\n        // Library invocation options\n        private final Map<String, Object> options;\n        private final InvocationMapper invocationMapper;\n        private final Map<Method, FunctionInfo> functions = new WeakHashMap<>();\n        public Handler(String libname, Class<?> interfaceClass, Map<String, ?> options) {\n\n            if (libname != null && \"\".equals(libname.trim())) {\n                throw new IllegalArgumentException(\"Invalid library name \\\"\" + libname + \"\\\"\");\n            }\n\n            if (!interfaceClass.isInterface()) {\n                throw new IllegalArgumentException(libname + \" does not implement an interface: \" + interfaceClass.getName());\n            }\n\n            this.interfaceClass = interfaceClass;\n            this.options = new HashMap<>(options);\n            int callingConvention = AltCallingConvention.class.isAssignableFrom(interfaceClass)\n                                  ? Function.ALT_CONVENTION\n                                  : Function.C_CONVENTION;\n            if (this.options.get(OPTION_CALLING_CONVENTION) == null) {\n                this.options.put(OPTION_CALLING_CONVENTION, Integer.valueOf(callingConvention));\n            }\n            if (this.options.get(OPTION_CLASSLOADER) == null) {\n                this.options.put(OPTION_CLASSLOADER, interfaceClass.getClassLoader());\n            }\n            this.nativeLibrary = NativeLibrary.getInstance(libname, this.options);","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Library.java#L161-L197","documentation":"Library.Handler's constructor validates the native library name and throws this IllegalArgumentException when the name is null-trimmed to an empty string (non-null but blank). JNA requires either a real library name/path or null to mean 'link against the current process'.","triggerScenarios":"Native.load(\"\", Iface.class) or Native.load(\"   \", Iface.class); loading a library via a config/property that resolved to whitespace; calling Native.loadLibrary with a blank name.","commonSituations":"Library name pulled from an environment variable or properties file that is blank; string concatenation producing an empty name; mistaking \"\" for the null meaning of 'current process'.","solutions":["Pass a real library name (without platform prefix/suffix) or full path to Native.load.","If you intend to bind to the current process, pass null explicitly, not \"\".","Trim/validate the configured name and fail fast with a clear config error before calling Native.load."],"exampleFix":"// before\nString lib = System.getProperty(\"lib.name\"); // may be \"\"\nMyLib lib = Native.load(lib, MyLib.class);\n// after\nString lib = System.getProperty(\"lib.name\", \"mylib\").trim();\nMyLib lib = Native.load(lib.isEmpty() ? null : lib, MyLib.class);","handlingStrategy":"validation","validationCode":"static String requireLibName(String name) {\n  if (name == null || name.trim().isEmpty())\n    throw new IllegalArgumentException(\"Native library name must be non-blank (use null explicitly for current process)\");\n  return name.trim();\n}","typeGuard":null,"tryCatchPattern":"try {\n  MyLib lib = Native.load(name, MyLib.class);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid library name\")) {\n    throw new IllegalStateException(\"Configured library name is blank; check the lib.name setting\", e);\n  }\n  throw e;\n}","preventionTips":["Trim and default-check configured library names before Native.load.","Pass null (not \"\") to bind to the current process.","Fail fast at config-load time if the name is blank.","Log the resolved name at startup."],"tags":["jna","native-library","library-loading","invalid-name"],"backgroundTag":"invalid-config-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"}