{"record":{"id":"12ba8531d9e5a8bc","repo":"karatelabs/karate","slug":"failed-to-read-item-at-index-index","errorCode":null,"errorMessage":"failed to read item at index ${index}","messagePattern":"failed to read item at index (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java","lineNumber":193,"sourceCode":"\n    @Override\n    public Object get(int index) {\n        if (closed) {\n            throw new IllegalStateException(\"store has been closed\");\n        }\n        if (index < 0 || index >= size) {\n            throw new IndexOutOfBoundsException(\"index: \" + index + \", size: \" + size);\n        }\n        try {\n            if (raf == null) {\n                raf = new RandomAccessFile(tempFile, \"r\");\n            }\n            long offset = lineOffsets.get(index);\n            raf.seek(offset);\n            String line = raf.readLine();\n            return deserializeItem(line);\n        } catch (IOException e) {\n            throw new RuntimeException(\"failed to read item at index \" + index, e);\n        }\n    }\n\n    @Override\n    public Iterator<Object> iterator() {\n        if (closed) {\n            throw new IllegalStateException(\"store has been closed\");\n        }\n        return new DiskBackedIterator();\n    }\n\n    @Override\n    public void close() {\n        if (closed) {\n            return;\n        }\n        closed = true;\n        if (raf != null) {","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/DiskBackedList.java#L175-L211","documentation":"DiskBackedList.get() wraps any IOException raised while seeking/reading the backing temp file in a RuntimeException with this message, chaining the original IOException as cause. It means the on-disk serialized line for that index could not be read.","triggerScenarios":"The temp file was deleted or truncated after list creation (e.g. temp dir cleanup); disk I/O error; file descriptor exhausted; underlying filesystem became unavailable mid-read.","commonSituations":"Long-lived lists whose temp files got cleaned by OS/tmp reapers; containers with small or volatile /tmp; running out of file handles under load.","solutions":["Inspect the chained IOException cause for the root reason","Keep the DiskBackedList short-lived and close it deterministically after use","Configure java.io.tmpdir to a stable location not subject to aggressive cleanup","Ensure temp files are not deleted externally while the list is alive"],"exampleFix":"// before\nDiskBackedList list = new DiskBackedList(items, new File(\"/tmp/cache\"));\n// after\nFile dir = new File(System.getProperty(\"java.io.tmpdir\")); // stable, app-managed\nDiskBackedList list = new DiskBackedList(items, dir);","handlingStrategy":"try-catch","validationCode":"File temp = backingFileOf(list);\nif (temp == null || !temp.exists() || !temp.canRead()) throw new IOException(\"backing file unavailable: \" + temp);","typeGuard":"boolean readable(File f) { return f != null && f.isFile() && f.canRead(); }","tryCatchPattern":"try { return list.get(i); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { log.error(\"disk read failed for index \" + i, e.getCause()); } throw e; }","preventionTips":["Use a stable java.io.tmpdir excluded from cleanup","Keep list lifetime short; close promptly","Monitor the chained IOException cause for root cause","Ensure adequate disk space and file descriptors"],"tags":["io","file-read","runtime-exception","temp-file"],"backgroundTag":"file-read-failed","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"}