{"record":{"id":"ef58fb24e7f48b30","repo":"skylot/jadx","slug":"failed-to-save-temp-file","errorCode":null,"errorMessage":"Failed to save temp file","messagePattern":"Failed to save temp file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/api/plugins/utils/CommonFileUtils.java","lineNumber":42,"sourceCode":"\t\t\treturn new File(\".\").getCanonicalFile();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Failed to init current working dir constant\", e);\n\t\t}\n\t}\n\n\tpublic static Path saveToTempFile(InputStream in, String suffix) throws IOException {\n\t\treturn saveToTempFile(null, in, suffix);\n\t}\n\n\tpublic static Path saveToTempFile(byte[] dataPrefix, InputStream in, String suffix) throws IOException {\n\t\tPath tempFile = Files.createTempFile(\"jadx-temp-\", suffix);\n\t\ttry (OutputStream out = Files.newOutputStream(tempFile)) {\n\t\t\tif (dataPrefix != null) {\n\t\t\t\tout.write(dataPrefix);\n\t\t\t}\n\t\t\tcopyStream(in, out);\n\t\t} catch (Exception e) {\n\t\t\tthrow new IOException(\"Failed to save temp file\", e);\n\t\t}\n\t\treturn tempFile;\n\t}\n\n\tpublic static boolean safeDeleteFile(File file) {\n\t\ttry {\n\t\t\treturn file.delete();\n\t\t} catch (Exception e) {\n\t\t\tLOG.warn(\"Failed to delete file: {}\", file, e);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tpublic static byte[] loadBytes(InputStream input) throws IOException {\n\t\treturn loadBytes(null, input);\n\t}\n\n\tpublic static byte[] loadBytes(byte[] dataPrefix, InputStream in) throws IOException {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/api/plugins/utils/CommonFileUtils.java#L24-L60","documentation":"Thrown by CommonFileUtils.saveToTempFile when writing the input stream (and optional data prefix) to a newly created temp file fails. The method first creates a temp file via Files.createTempFile, then wraps any exception during the write (OutputStream operations or copyStream) in an IOException with this message. The original exception is preserved as the cause.","triggerScenarios":"The temp file is created but writing fails due to disk full, permission revoked on the temp directory, the input stream throwing during read, or the output stream being closed unexpectedly. The catch covers out.write(dataPrefix), copyStream(in, out), and the try-with-resources close. Note that Files.createTempFile failures (before the try) are NOT wrapped by this message — they propagate directly.","commonSituations":"Temp directory (/tmp or java.io.tmpdir) is full or read-only. The InputStream provided is already closed or reads from a corrupted zip entry. Running jadx in a container with limited writable storage. Large APK inputs that exhaust disk space during temp file writing.","solutions":["Check available disk space in the system temp directory (java.io.tmpdir).","Set -Djava.io.tmpdir to a directory with sufficient space and write permissions.","Verify the InputStream is open and readable before calling saveToTempFile; for zip entries, check the entry is valid.","Inspect getCause() on the IOException to distinguish disk I/O errors from stream-reading errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check temp directory is writable and has space before calling saveToTempFile\nPath tmpDir = Path.of(System.getProperty(\"java.io.tmpdir\"));\nFileStore store = Files.getFileStore(tmpDir);\nif (store.getUsableSpace() < estimatedSize) {\n    throw new IOException(\"Insufficient temp space in \" + tmpDir);\n}","typeGuard":null,"tryCatchPattern":"Path tempFile;\ntry {\n    tempFile = CommonFileUtils.saveToTempFile(inputStream, \".tmp\");\n} catch (IOException e) {\n    LOG.error(\"Failed to save temp file: {}\", e.getCause().getMessage());\n    throw e;\n}","preventionTips":["Set -Djava.io.tmpdir to a directory with sufficient free disk space for large APK processing.","Verify the InputStream is open and readable before passing it to saveToTempFile.","Inspect getCause() to distinguish disk-full/permission errors from input-stream read errors."],"tags":["io","tempfile","filesystem"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}