{"record":{"id":"4d335e374610da3c","repo":"skylot/jadx","slug":"failed-to-create-non-prefixed-temp-file-filenam","errorCode":null,"errorMessage":"Failed to create non-prefixed temp file: ${fileName}","messagePattern":"Failed to create non-prefixed temp file: (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java","lineNumber":295,"sourceCode":"\t\ttry {\n\t\t\treturn Files.createTempFile(Files.createTempDirectory(\"jadx-persist\"), \"jadx-\", suffix);\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to create temp file with suffix: \" + suffix, e);\n\t\t}\n\t}\n\n\t/**\n\t * Deprecated.\n\t * Migrate to {@link IJadxFilesGetter} from jadx args to get temp dir\n\t */\n\t@Deprecated\n\tpublic static Path createTempFileNonPrefixed(String fileName) {\n\t\ttry {\n\t\t\tPath path = Files.createFile(tempRootDir.resolve(fileName));\n\t\t\tpath.toFile().deleteOnExit();\n\t\t\treturn path;\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to create non-prefixed temp file: \" + fileName, e);\n\t\t}\n\t}\n\n\tpublic static void copyStream(InputStream input, OutputStream output) throws IOException {\n\t\tbyte[] buffer = new byte[READ_BUFFER_SIZE];\n\t\twhile (true) {\n\t\t\tint count = input.read(buffer);\n\t\t\tif (count == -1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\toutput.write(buffer, 0, count);\n\t\t}\n\t}\n\n\tpublic static byte[] streamToByteArray(InputStream input) throws IOException {\n\t\treturn input.readAllBytes();\n\t}\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java#L277-L313","documentation":"Thrown by createTempFileNonPrefixed(String fileName) when Files.createFile(tempRootDir.resolve(fileName)) fails. Unlike the other temp methods, this creates a file with an EXACT user-specified name (no random suffix). Files.createFile fails if the file already exists (FileAlreadyExistsException), if fileName contains path separators resolving outside tempRootDir, if tempRootDir is missing/unwritable, or if the name is invalid.","triggerScenarios":"Calling createTempFileNonPrefixed with a fileName that already exists in tempRootDir. A fileName containing '/' or '\\' that resolves to a path outside tempRootDir. tempRootDir deleted. An OS-illegal filename character in fileName.","commonSituations":"Calling the method twice with the same fileName in one JVM session (second call fails because file exists). A fileName containing a path separator from user input. Long-running process where tempRootDir was cleared. Deprecated API not migrated.","solutions":["Migrate to IJadxFilesGetter from jadx args.","Ensure the fileName is unique per session — append a UUID or timestamp if calling repeatedly.","Strip path separators from fileName before calling.","Check Files.exists(tempRootDir.resolve(fileName)) and handle the collision."],"exampleFix":"// before (fails on second call with same name)\nPath tmp = FileUtils.createTempFileNonPrefixed(\"cache.dex\");\n\n// after — make name unique\nString uniqueName = \"cache-\" + UUID.randomUUID() + \".dex\";\nPath tmp = FileUtils.createTempFileNonPrefixed(uniqueName);","handlingStrategy":"validation","validationCode":"public static String uniqueTempFileName(String baseName) {\n    int dot = baseName.lastIndexOf('.');\n    String prefix = dot > 0 ? baseName.substring(0, dot) : baseName;\n    String ext = dot > 0 ? baseName.substring(dot) : \"\";\n    return prefix + \"-\" + System.nanoTime() + ext;\n}\n\npublic static boolean tempFileNameAvailable(String fileName) {\n    // requires access to tempRootDir which is package-private\n    return !fileName.contains(\"/\") && !fileName.contains(\"\\\\\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Path tmp = FileUtils.createTempFileNonPrefixed(fileName);\n} catch (JadxRuntimeException e) {\n    if (e.getCause() instanceof FileAlreadyExistsException) {\n        fileName = \"copy-\" + fileName;\n        Path tmp = FileUtils.createTempFileNonPrefixed(fileName);\n    } else throw e;\n}","preventionTips":["Make fileNames unique per call by appending a UUID or nanoTime.","Strip path separators from fileName.","Migrate to IJadxFilesGetter as the method is deprecated."],"tags":["temp-file","deprecated","filesystem","file-conflict","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}