skylot/jadx · error · JadxRuntimeException

Failed to create non-prefixed temp file: ${fileName}

Error message

Failed to create non-prefixed temp file: ${fileName}

What it means

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.

Source

Thrown at jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java:295

		try {
			return Files.createTempFile(Files.createTempDirectory("jadx-persist"), "jadx-", suffix);
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to create temp file with suffix: " + suffix, e);
		}
	}

	/**
	 * Deprecated.
	 * Migrate to {@link IJadxFilesGetter} from jadx args to get temp dir
	 */
	@Deprecated
	public static Path createTempFileNonPrefixed(String fileName) {
		try {
			Path path = Files.createFile(tempRootDir.resolve(fileName));
			path.toFile().deleteOnExit();
			return path;
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to create non-prefixed temp file: " + fileName, e);
		}
	}

	public static void copyStream(InputStream input, OutputStream output) throws IOException {
		byte[] buffer = new byte[READ_BUFFER_SIZE];
		while (true) {
			int count = input.read(buffer);
			if (count == -1) {
				break;
			}
			output.write(buffer, 0, count);
		}
	}

	public static byte[] streamToByteArray(InputStream input) throws IOException {
		return input.readAllBytes();
	}

View on GitHub (pinned to e738a26571)

Solutions

  1. Migrate to IJadxFilesGetter from jadx args.
  2. Ensure the fileName is unique per session — append a UUID or timestamp if calling repeatedly.
  3. Strip path separators from fileName before calling.
  4. Check Files.exists(tempRootDir.resolve(fileName)) and handle the collision.

Example fix

// before (fails on second call with same name)
Path tmp = FileUtils.createTempFileNonPrefixed("cache.dex");

// after — make name unique
String uniqueName = "cache-" + UUID.randomUUID() + ".dex";
Path tmp = FileUtils.createTempFileNonPrefixed(uniqueName);
Defensive patterns

Strategy: validation

Validate before calling

public static String uniqueTempFileName(String baseName) {
    int dot = baseName.lastIndexOf('.');
    String prefix = dot > 0 ? baseName.substring(0, dot) : baseName;
    String ext = dot > 0 ? baseName.substring(dot) : "";
    return prefix + "-" + System.nanoTime() + ext;
}

public static boolean tempFileNameAvailable(String fileName) {
    // requires access to tempRootDir which is package-private
    return !fileName.contains("/") && !fileName.contains("\\");
}

Try / catch

try {
    Path tmp = FileUtils.createTempFileNonPrefixed(fileName);
} catch (JadxRuntimeException e) {
    if (e.getCause() instanceof FileAlreadyExistsException) {
        fileName = "copy-" + fileName;
        Path tmp = FileUtils.createTempFileNonPrefixed(fileName);
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/4d335e374610da3c. Report an issue: GitHub.