{"record":{"id":"473215a92424d5c6","repo":"java-native-access/jna","slug":"failed-to-create-temporary-file-for-name-library-e","errorCode":null,"errorMessage":"Failed to create temporary file for name library: e.getMessage()","messagePattern":"Failed to create temporary file for name library: e\\.getMessage\\(\\)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":1252,"sourceCode":"            try {\n                // Suffix is required on windows, or library fails to load\n                // Let Java pick the suffix, except on windows, to avoid\n                // problems with Web Start.\n                File dir = getTempDir();\n                lib = File.createTempFile(JNA_TMPLIB_PREFIX, Platform.isWindows()?\".dll\":null, dir);\n                if (!Boolean.getBoolean(\"jnidispatch.preserve\")) {\n                    lib.deleteOnExit();\n                }\n                LOG.log(DEBUG, \"Extracting library to {0}\", lib.getAbsolutePath());\n                fos = new FileOutputStream(lib);\n                int count;\n                byte[] buf = new byte[1024];\n                while ((count = is.read(buf, 0, buf.length)) > 0) {\n                    fos.write(buf, 0, count);\n                }\n            }\n            catch(IOException e) {\n                throw new IOException(\"Failed to create temporary file for \" + name + \" library: \" + e.getMessage());\n            }\n            finally {\n                try { is.close(); } catch(IOException e) { }\n                if (fos != null) {\n                    try { fos.close(); } catch(IOException e) { }\n                }\n            }\n        }\n        return lib;\n    }\n\n    /**\n     * Initialize field and method IDs for native methods of this class.\n     * Returns the size of a native pointer.\n     **/\n    private static native int sizeof(int type);\n\n    private static native String getNativeVersion();","sourceCodeStart":1234,"sourceCodeEnd":1270,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L1234-L1270","documentation":"While unpacking the native library resource to a temporary file, any IOException encountered (creating the temp file or writing the buffered stream) is wrapped as IOException 'Failed to create temporary file for <name> library: <reason>'. The native library could not be materialized on disk, so loading cannot proceed.","triggerScenarios":"extractFromResourcePath stream-copy loop failing because the temp directory is read-only, full, or File.createTempFile failed; disk quota exceeded; antivirus/permissions blocking file creation in java.io.tmpdir.","commonSituations":"Containers with read-only /tmp; tmpwatch cleaner races; small tmpfs; corporate policy denying execute from temp; running as a user without write access to the temp dir.","solutions":["Set -Djna.tmpdir (or java.io.tmpdir) to a writable, executable directory and retry","Free disk space / raise quota on the temp filesystem","If the library is already unpacked on disk, set -Djna.nounpack=true and point jna.boot.library.path at it","Check the embedded reason in the message (permission vs space) and fix filesystem permissions accordingly"],"exampleFix":"// before\njava -jar app.jar  # tmpdir read-only\n// after\njava -Djna.tmpdir=/var/lib/app/tmp -jar app.toml -> ensure /var/lib/app/tmp is writable and mounted with exec","handlingStrategy":"validation","validationCode":"// ensure temp dir is writable before first JNA call\nFile tmp = new File(System.getProperty(\"jna.tmpdir\", System.getProperty(\"java.io.tmpdir\")));\nif (!tmp.canWrite()) throw new IllegalStateException(\"JNA temp dir not writable: \" + tmp);\nif (tmp.getUsableSpace() < 10L * 1024 * 1024) throw new IllegalStateException(\"Low space in JNA temp dir: \" + tmp);","typeGuard":null,"tryCatchPattern":"try { Native.load(\"c\", CLibrary.class); } catch (UnsatisfiedLinkError e) { Throwable c = e; while ((c = c.getCause()) != null) { if (c instanceof IOException && String.valueOf(c.getMessage()).contains(\"Failed to create temporary file\")) { throw new IllegalStateException(\"Fix jna.tmpdir permissions/space\", e); } } throw e; }","preventionTips":["Set -Djna.tmpdir to a dedicated writable directory with exec permission","Monitor temp filesystem space in containers","Use -Djna.nounpack with a pre-installed native library in restricted environments"],"tags":["java","io","temp-file","unpacking"],"backgroundTag":"file-write-failed","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"}