{"record":{"id":"774042759b2dce99","repo":"apache/iceberg","slug":"failed-to-read-json-file-s","errorCode":null,"errorMessage":"Failed to read json file: %s","messagePattern":"Failed to read json file: (.+?)","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/view/ViewMetadataParser.java","lineNumber":183,"sourceCode":"  public static void overwrite(ViewMetadata metadata, OutputFile outputFile) {\n    internalWrite(metadata, outputFile, true);\n  }\n\n  public static void write(ViewMetadata metadata, OutputFile outputFile) {\n    internalWrite(metadata, outputFile, false);\n  }\n\n  public static ViewMetadata read(FileIO io, String path) {\n    return read(io.newInputFile(path));\n  }\n\n  public static ViewMetadata read(InputFile file) {\n    Codec codec = Codec.fromFileName(file.location());\n    try (InputStream is =\n        codec == Codec.GZIP ? new GZIPInputStream(file.newStream()) : file.newStream()) {\n      return fromJson(file.location(), JsonUtil.mapper().readValue(is, JsonNode.class));\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          String.format(\"Failed to read json file: %s\", file.location()), e);\n    }\n  }\n\n  private static void internalWrite(\n      ViewMetadata metadata, OutputFile outputFile, boolean overwrite) {\n    boolean isGzip = Codec.fromFileName(outputFile.location()) == Codec.GZIP;\n    OutputStream stream = overwrite ? outputFile.createOrOverwrite() : outputFile.create();\n    try (OutputStreamWriter writer =\n            new OutputStreamWriter(\n                isGzip ? new GZIPOutputStream(stream) : stream, StandardCharsets.UTF_8);\n        JsonGenerator generator = JsonUtil.factory().createGenerator(writer)) {\n      toJson(metadata, generator);\n      generator.flush();\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          String.format(\"Failed to write json to file: %s\", outputFile.location()), e);\n    }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/view/ViewMetadataParser.java#L165-L201","documentation":"ViewMetadataParser.read wraps any IOException encountered while opening/reading the view metadata JSON file in an UncheckedIOException with this message. It indicates the view metadata file at the given location could not be read (missing file, permissions, corrupt/gzip stream, malformed JSON).","triggerScenarios":"Calling ViewMetadataParser.read(InputFile) where the file does not exist, is unreadable, gzip decoding fails, or the content is not valid JSON matching the view metadata schema.","commonSituations":"Registering a view from a wrong/typoed metadata file location; metadata deleted by retention jobs before registration; reading a metadata file across clusters with different credentials; corrupted object storage object.","solutions":["Verify the metadata file location exists and is accessible with the configured FileIO credentials","Check whether the file is gzip-compressed consistently with its name/extension","Validate the JSON content parses and matches the view metadata schema","Re-export or re-create the metadata file if it is corrupt"],"exampleFix":"// before\nViewMetadata meta = ViewMetadataParser.read(file);\n// after\nif (!file.exists()) {\n  throw new IllegalArgumentException(\"Missing view metadata: \" + file.location());\n}\ntry {\n  ViewMetadata meta = ViewMetadataParser.read(file);\n} catch (UncheckedIOException e) {\n  throw new IllegalStateException(\"Corrupt view metadata: \" + file.location(), e);\n}","handlingStrategy":"try-catch","validationCode":"try (InputStream in = file.newStream()) { JsonUtil.mapper().readTree(in); } catch (Exception e) { /* location unreadable or invalid */ }","typeGuard":null,"tryCatchPattern":"try { ViewMetadataParser.read(file); } catch (UncheckedIOException e) { throw new IllegalStateException(\"Unreadable view metadata: \" + file.location(), e); }","preventionTips":["Verify metadata file location and credentials before parsing","Confirm file is gzip only when the name/codec says so","Validate JSON against the view metadata schema after unusual events"],"tags":["io","json","file-read","view-metadata"],"backgroundTag":"file-read-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"}