{"record":{"id":"adcd79c01fc84282","repo":"apache/iceberg","slug":"failed-to-open-file-s-adcd79","errorCode":null,"errorMessage":"Failed to open file: %s","messagePattern":"Failed to open file: (.+?)","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/io/ContentCache.java","lineNumber":214,"sourceCode":"    }\n\n    /**\n     * Opens a new {@link SeekableInputStream} for the underlying data file, either from cache or\n     * from the inner FileIO.\n     *\n     * <p>If data file is not cached yet, and it can fit in the cache, the file content will be\n     * cached first before returning a {@link ByteBufferInputStream}. Otherwise, return a new\n     * SeekableInputStream from the inner FIleIO.\n     *\n     * @return a {@link ByteBufferInputStream} if file exist in the cache or can fit in the cache.\n     *     Otherwise, return a new SeekableInputStream from the inner FIleIO.\n     */\n    @Override\n    public SeekableInputStream newStream() {\n      try {\n        return cachedStream();\n      } catch (FileNotFoundException e) {\n        throw new NotFoundException(e, \"Failed to open file: %s\", input.location());\n      } catch (IOException e) {\n        return input.newStream();\n      }\n    }\n\n    @Override\n    public String location() {\n      return input.location();\n    }\n\n    @Override\n    public boolean exists() {\n      FileContent buf = contentCache.cache.getIfPresent(input.location());\n      return buf != null || input.exists();\n    }\n\n    private SeekableInputStream cachedStream() throws IOException {\n      try {","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/io/ContentCache.java#L196-L232","documentation":"ContentCache.newStream wraps a FileNotFoundException from the cached-stream path into a NotFoundException, meaning the file could not be opened even though a cached read was attempted. Any other IOException falls back to the uncached delegate stream instead of failing.","triggerScenarios":"Calling newStream() on a caching InputFile whose underlying file is missing (deleted between planning and read, wrong path, or not yet visible), and cachedStream() propagates FileNotFoundException.","commonSituations":"Reading a data file deleted by compaction/expiry while a long-running scan still references it; mistyped or stale file location; eventual-consistency lag after write in S3-compatible stores.","solutions":["Verify the file location exists in storage (ls/stat the object) before or at read time.","Re-plan the scan to get a fresh snapshot; the file may have been expired.","Check for concurrent table maintenance (expireSnapshots/rewriteDataFiles) racing readers.","Fix path/region configuration if the location is systematically wrong."],"exampleFix":"// before\nSeekableInputStream in = cacheFile.newStream(); // NotFoundException\n// after\nif (!io.newInputFile(location).exists()) {\n  LOG.warn(\"File {} missing, re-planning scan\", location);\n  return replanAndRead(location);\n}\nSeekableInputStream in = cacheFile.newStream();","handlingStrategy":"fallback","validationCode":"boolean exists = io.newInputFile(location).exists();\nif (!exists) { replanOrSkip(location); }","typeGuard":null,"tryCatchPattern":"try {\n  return cachedFile.newStream();\n} catch (NotFoundException e) {\n  LOG.warn(\"File {} not found, falling back to replan\", location);\n  return replannedFile.newStream();\n}","preventionTips":["Don't expire snapshots/rewrite files while long scans are running","Pin reads to a snapshot ID to avoid reading expired files","Verify locations after cloning/copying tables across buckets","Watch for eventual-consistency lag on S3-compatible stores"],"tags":["file-not-found","cache","io"],"backgroundTag":"file-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}