karatelabs/karate · error · RuntimeException
temp file not found
Error message
temp file not found
What it means
DiskBackedList's DiskBackedIterator constructor wraps FileNotFoundException from opening the backing temp file in a RuntimeException reading 'temp file not found'. The iterator needs to reopen the temp file for sequential reading, and it is gone at iteration time.
Solutions
- Check the chained FileNotFoundException for the missing path
- Keep list lifetime short and iterate promptly after creation
- Point java.io.tmpdir at an app-managed directory excluded from cleanup
- Do not close/delete the backing file before all iterators are done
Example fix
// before
File f = File.createTempFile("kdbl", ".tmp", new File("/tmp/shared"));
// after
File f = File.createTempFile("kdbl", ".tmp", appManagedDir); // not auto-cleaned Defensive patterns
Strategy: validation
Validate before calling
File f = backingFileOf(list);
if (f == null || !f.exists()) throw new FileNotFoundException("backing temp file gone: " + f); Type guard
boolean tempFilePresent(DiskBackedList l, File f) { return f != null && f.exists(); } Try / catch
try { for (Object o : list) process(o); } catch (RuntimeException e) { if ("temp file not found".equals(e.getMessage())) { log.error("backing temp file was deleted; recreate the list", e.getCause()); } throw e; } Prevention
- Point java.io.tmpdir at an app-managed, cleaner-excluded directory
- Iterate promptly after list creation
- Prevent external deletion of the backing file while in use
When it happens
Trigger: The temp file was deleted between list creation and iterator construction (external cleanup, same-process delete, container tmp reaping); close() deleted the file and an old iterator is reused; temp directory recreated/cleared.
Common situations: Long-running jobs iterating lazily long after list creation; /tmp cleaners (systemd-tmpfiles) deleting files; multiple lists sharing a directory that gets wiped.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- failed to read next line
- failed to read item at index
- boot.read: file not found
- boot.read: file not found
- Failed to read bytes from
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/bb5924e1c6255707.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java:237
if (tempFile.exists()) {
if (!tempFile.delete()) {
logger.warn("failed to delete temp file: {}", tempFile);
}
}
}
private class DiskBackedIterator implements Iterator<Object> {
private final BufferedReader reader;
private int currentIndex = 0;
private String nextLine = null;
private boolean hasNextCalled = false;
DiskBackedIterator() {
try {
reader = new BufferedReader(
new InputStreamReader(new FileInputStream(tempFile), StandardCharsets.UTF_8));
} catch (FileNotFoundException e) {
throw new RuntimeException("temp file not found", e);
}
}
@Override
public boolean hasNext() {
if (hasNextCalled) {
return nextLine != null;
}
hasNextCalled = true;
if (currentIndex >= size) {
closeReader();
return false;
}
try {
nextLine = reader.readLine();
if (nextLine == null) {
closeReader();
return false;View on GitHub (pinned to a22eb90246)