{"record":{"id":"8a03835bc920bcc6","repo":"apache/iceberg","slug":"failed-to-open-input-stream-for-file-s","errorCode":null,"errorMessage":"Failed to open input stream for file: %s","messagePattern":"Failed to open input stream for file: (.+?)","errorType":"exception","errorClass":"NotFoundException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopInputFile.java","lineNumber":187,"sourceCode":"      }\n    }\n    return stat;\n  }\n\n  @Override\n  public long getLength() {\n    if (length == null) {\n      this.length = lazyStat().getLen();\n    }\n    return length;\n  }\n\n  @Override\n  public SeekableInputStream newStream() {\n    try {\n      return HadoopStreams.wrap(fs.open(path));\n    } catch (FileNotFoundException e) {\n      throw new NotFoundException(e, \"Failed to open input stream for file: %s\", path);\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Failed to open input stream for file: %s\", path);\n    }\n  }\n\n  @Override\n  public Configuration getConf() {\n    return conf;\n  }\n\n  @Override\n  public void serializeConfWith(\n      Function<Configuration, SerializableSupplier<Configuration>> confSerializer) {\n    throw new UnsupportedOperationException(\"Cannot serialize a Hadoop input file: \" + location());\n  }\n\n  public FileSystem getFileSystem() {\n    return fs;","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopInputFile.java#L169-L205","documentation":"HadoopInputFile.newStream opens a SeekableInputStream via fs.open(path). FileNotFoundException becomes NotFoundException (a missing file), while any other IOException becomes this RuntimeIOException. Both use the same 'Failed to open input stream' message, so check the exception type/cause to distinguish missing-file from I/O trouble.","triggerScenarios":"Calling newStream() on a file deleted between exists() and open, on a path with wrong scheme/authority, or when the FS client fails (auth expiry, throttling, permission denied, checksum errors on HDFS).","commonSituations":"Readers racing with expireSnapshots/orphan cleanup; long-running Spark jobs whose Kerberos or cloud credentials expire; S3 throttling during large parallel reads; cluster decommissioning making files unreachable.","solutions":["Check the exception cause: FileNotFoundException means the file is gone — refresh table metadata or restore the file.","Other causes (throttling, auth, permissions): refresh credentials, verify permissions, and retry with backoff.","Ensure cleanup jobs don't delete files still covered by active snapshots; set proper retention windows.","Confirm scheme/authority/region configuration matches the storage where files were written.","Use table rollback to a snapshot whose files still exist if files were permanently lost."],"exampleFix":"// before\nSeekableInputStream in = io.newInputFile(path).newStream();\n// after\ntry {\n  SeekableInputStream in = io.newInputFile(path).newStream();\n} catch (NotFoundException e) {\n  table.refresh(); // metadata may reference a deleted file\n  throw e;\n} catch (RuntimeIOException e) {\n  // transient FS/auth issue: refresh creds and retry\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"InputFile f = io.newInputFile(path);\nif (!f.exists()) { /* avoid newStream: file missing */ }","typeGuard":null,"tryCatchPattern":"try (SeekableInputStream in = io.newInputFile(path).newStream()) {\n  // read\n} catch (NotFoundException e) {\n  // file missing: refresh metadata / rollback snapshot\n} catch (RuntimeIOException e) {\n  // transient IO/auth: refresh creds, retry with backoff\n}","preventionTips":["Always open streams inside try-with-resources.","Ensure cleanup jobs don't delete files for live snapshots.","Refresh credentials/tokens for jobs longer than the token lifetime.","Verify scheme/authority/region correctness before deployment."],"tags":["io","file-open","hadoop","input-file"],"backgroundTag":"file-open-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}