{"record":{"id":"bb5924e1c6255707","repo":"karatelabs/karate","slug":"temp-file-not-found","errorCode":null,"errorMessage":"temp file not found","messagePattern":"temp file not found","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java","lineNumber":237,"sourceCode":"        if (tempFile.exists()) {\n            if (!tempFile.delete()) {\n                logger.warn(\"failed to delete temp file: {}\", tempFile);\n            }\n        }\n    }\n\n    private class DiskBackedIterator implements Iterator<Object> {\n        private final BufferedReader reader;\n        private int currentIndex = 0;\n        private String nextLine = null;\n        private boolean hasNextCalled = false;\n\n        DiskBackedIterator() {\n            try {\n                reader = new BufferedReader(\n                        new InputStreamReader(new FileInputStream(tempFile), StandardCharsets.UTF_8));\n            } catch (FileNotFoundException e) {\n                throw new RuntimeException(\"temp file not found\", e);\n            }\n        }\n\n        @Override\n        public boolean hasNext() {\n            if (hasNextCalled) {\n                return nextLine != null;\n            }\n            hasNextCalled = true;\n            if (currentIndex >= size) {\n                closeReader();\n                return false;\n            }\n            try {\n                nextLine = reader.readLine();\n                if (nextLine == null) {\n                    closeReader();\n                    return false;","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java#L219-L255","documentation":"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.","triggerScenarios":"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.","commonSituations":"Long-running jobs iterating lazily long after list creation; /tmp cleaners (systemd-tmpfiles) deleting files; multiple lists sharing a directory that gets wiped.","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"],"exampleFix":"// before\nFile f = File.createTempFile(\"kdbl\", \".tmp\", new File(\"/tmp/shared\"));\n// after\nFile f = File.createTempFile(\"kdbl\", \".tmp\", appManagedDir); // not auto-cleaned","handlingStrategy":"validation","validationCode":"File f = backingFileOf(list);\nif (f == null || !f.exists()) throw new FileNotFoundException(\"backing temp file gone: \" + f);","typeGuard":"boolean tempFilePresent(DiskBackedList l, File f) { return f != null && f.exists(); }","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["io","file-not-found","temp-file","iterator"],"backgroundTag":"file-not-found","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}