{"record":{"id":"a5dc56252c2bd15f","repo":"apache/iceberg","slug":"failed-to-open-file-s-a5dc56","errorCode":null,"errorMessage":"Failed to open file: %s","messagePattern":"Failed to open file: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"orc/src/main/java/org/apache/iceberg/orc/OrcMetrics.java","lineNumber":104,"sourceCode":"    final Configuration config =\n        (file instanceof HadoopInputFile)\n            ? ((HadoopInputFile) file).getConf()\n            : new Configuration();\n    return fromInputFile(file, config, metricsConfig, mapping);\n  }\n\n  static Metrics fromInputFile(\n      InputFile file, Configuration config, MetricsConfig metricsConfig, NameMapping mapping) {\n    try (Reader orcReader = ORC.newFileReader(file, config)) {\n      return buildOrcMetrics(\n          orcReader.getNumberOfRows(),\n          orcReader.getSchema(),\n          orcReader.getStatistics(),\n          Stream.empty(),\n          metricsConfig,\n          mapping);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(ioe, \"Failed to open file: %s\", file.location());\n    }\n  }\n\n  static Metrics fromWriter(\n      Writer writer, Stream<FieldMetrics<?>> fieldMetricsStream, MetricsConfig metricsConfig) {\n    try {\n      return buildOrcMetrics(\n          writer.getNumberOfRows(),\n          writer.getSchema(),\n          writer.getStatistics(),\n          fieldMetricsStream,\n          metricsConfig,\n          null);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(ioe, \"Failed to get statistics from writer\");\n    }\n  }\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/orc/src/main/java/org/apache/iceberg/orc/OrcMetrics.java#L86-L122","documentation":"OrcMetrics.fromInputFile opens the ORC file solely to compute file-level metrics (row count, column stats). If the ORC Reader cannot be opened — missing file, corrupt footer, or storage IOException — the exception is wrapped in RuntimeIOException including the file location. Metrics collection is decoupled from actual data reads, so this can surface during commit/metadata operations.","triggerScenarios":"Calling OrcMetrics.fromInputFile(file, metricsConfig, mapping) on an InputFile that fails to open as ORC: file not found, deleted object, truncated/corrupt footer, or storage access error (permissions, credentials, network).","commonSituations":"Metadata/commit tasks computing metrics for files that expired or were deleted on S3; corrupt ORC files from interrupted writes; wrong path or bucket configuration; missing cloud credentials.","solutions":["Check the wrapped cause and verify the file exists and is a valid ORC file at the given location.","Fix storage access: permissions, credentials, or bucket/path configuration used to build the InputFile.","If the file is corrupt or deleted, remove it from the table/manifest set or rewrite it from a backup; retry transient storage failures."],"exampleFix":"// before\nMetrics m = OrcMetrics.fromInputFile(file, metricsConfig, mapping); // RuntimeIOException if unopenable\n\n// after\nif (!file.exists()) {\n  throw new IllegalStateException(\"Input file missing: \" + file.location());\n}\nMetrics m = OrcMetrics.fromInputFile(file, metricsConfig, mapping);","handlingStrategy":"validation","validationCode":"if (!file.exists()) {\n  throw new IllegalStateException(\"Cannot compute metrics; file missing: \" + file.location());\n}","typeGuard":null,"tryCatchPattern":"try {\n  Metrics m = OrcMetrics.fromInputFile(file, metricsConfig, mapping);\n} catch (RuntimeIOException e) {\n  LOG.error(\"Cannot open ORC for metrics: {} cause: {}\", file.location(), e.getCause());\n  throw e;\n}","preventionTips":["Verify file existence and credentials before metric collection in commit tasks","Expire/delete files only after no running task references them","Handle corrupt files by quarantining and rewriting from source of truth"],"tags":["java","orc","metrics","file-open"],"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-14T21:17:11.552Z"}