{"record":{"id":"66a4c95af6446e58","repo":"java-native-access/jna","slug":"interface-interfacesimplename-of-library-name-does-not","errorCode":null,"errorMessage":"Interface (<interfaceSimpleName>) of library=<name> does not extend Library","messagePattern":"Interface \\(<interfaceSimpleName>\\) of library=<name> does not extend Library","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":685,"sourceCode":"     * the explicit interface class and a map of options for the library.\n     * If no library options are detected the map is interpreted as a map\n     * of Java method names to native function names.<p>\n     * If <code>name</code> is null, attempts to map onto the current process.\n     * Native libraries loaded via this method may be found in\n     * <a href=\"NativeLibrary.html#library_search_paths\">several locations</a>.\n     * @param <T> Type of expected wrapper\n     * @param name Library base name\n     * @param interfaceClass The implementation wrapper interface\n     * @param options Map of library options\n     * @return an instance of the requested interface, mapped to the indicated\n     * native library.\n     * @throws UnsatisfiedLinkError if the library cannot be found or\n     * dependent libraries are missing.\n     */\n    public static <T extends Library> T load(String name, Class<T> interfaceClass, Map<String, ?> options) {\n        if (!Library.class.isAssignableFrom(interfaceClass)) {\n            // Maybe still possible if the caller is not using generics?\n            throw new IllegalArgumentException(\"Interface (\" + interfaceClass.getSimpleName() + \")\"\n                    + \" of library=\" + name + \" does not extend \" + Library.class.getSimpleName());\n        }\n\n        Library.Handler handler = new Library.Handler(name, interfaceClass, options);\n        ClassLoader loader = interfaceClass.getClassLoader();\n        Object proxy = Proxy.newProxyInstance(loader, new Class[] {interfaceClass}, handler);\n        cacheOptions(interfaceClass, options, proxy);\n        return interfaceClass.cast(proxy);\n    }\n\n    /**\n     * Provided for improved compatibility between JNA 4.X and 5.X\n     *\n     * @see Native#load(java.lang.Class)\n     */\n    @Deprecated\n    public static <T> T loadLibrary(Class<T> interfaceClass) {\n        return loadLibrary(null, interfaceClass);","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L667-L703","documentation":"Native.load() requires the interface it wraps to extend com.sun.jna.Library so the proxy Handler can treat it as a native library mapping. If Library.class.isAssignableFrom(interfaceClass) is false, JNA throws IllegalArgumentException naming the interface and library.","triggerScenarios":"Calling Native.load(name, SomeInterface.class, options) where SomeInterface does not declare 'extends Library' — e.g. a plain interface of native methods, or extending the wrong marker interface.","commonSituations":"Migrating from loadLibrary to load and forgetting the extends Library clause; copying a mapped interface but dropping the Library parentage; defining the interface in a shared module without the JNA dependency hierarchy.","solutions":["Make the interface extend com.sun.jna.Library: interface MyLib extends Library { ... }.","If the type genuinely is not a library mapping, use the correct JNA API instead of Native.load.","Check generics so the compiler enforces <T extends Library> at the call site."],"exampleFix":"// before\npublic interface CLib { int getpid(); }\nCLib lib = Native.load(\"c\", CLib.class); // IllegalArgumentException\n// after\npublic interface CLib extends com.sun.jna.Library { int getpid(); }\nCLib lib = Native.load(\"c\", CLib.class);","handlingStrategy":"type-guard","validationCode":"if (!Library.class.isAssignableFrom(ifaceClass)) {\n    throw new IllegalArgumentException(ifaceClass + \" must extend Library before Native.load\");\n}\nT lib = Native.load(name, ifaceClass, options);","typeGuard":"<T> boolean isLibraryMapping(Class<T> c) {\n    return Library.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n    lib = Native.load(name, ifaceClass, options);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Define \" + ifaceClass.getSimpleName()\n        + \" as 'interface X extends Library': \" + e.getMessage());\n}","preventionTips":["Always declare native-library interfaces as 'interface X extends Library'.","Let the <T extends Library> generic bound catch mistakes at compile time by typing helper methods correctly.","Never bypass the generic bound with raw Class arguments."],"tags":["jna","library-mapping","illegal-argument","interface"],"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-19T12:17:13.211Z"}