{"record":{"id":"de99c0e555c67f20","repo":"apache/iceberg","slug":"failed-to-write-json-for-s","errorCode":null,"errorMessage":"Failed to write json for: %s","messagePattern":"Failed to write json for: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/TableMetadataParser.java","lineNumber":160,"sourceCode":"  }\n\n  public static String getFileExtension(Codec codec) {\n    return codec.extension + \".metadata.json\";\n  }\n\n  public static String getOldFileExtension(Codec codec) {\n    // we have to be backward-compatible with .metadata.json.gz files\n    return \".metadata.json\" + codec.extension;\n  }\n\n  public static String toJson(TableMetadata metadata) {\n    try (StringWriter writer = new StringWriter();\n        JsonGenerator generator = JsonUtil.factory().createGenerator(writer)) {\n      toJson(metadata, generator);\n      generator.flush();\n      return writer.toString();\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Failed to write json for: %s\", metadata);\n    }\n  }\n\n  @SuppressWarnings(\"checkstyle:CyclomaticComplexity\")\n  public static void toJson(TableMetadata metadata, JsonGenerator generator) throws IOException {\n    generator.writeStartObject();\n\n    generator.writeNumberField(FORMAT_VERSION, metadata.formatVersion());\n    generator.writeStringField(TABLE_UUID, metadata.uuid());\n    if (metadata.location() != null) {\n      generator.writeStringField(LOCATION, metadata.location());\n    }\n    if (metadata.formatVersion() > 1) {\n      generator.writeNumberField(LAST_SEQUENCE_NUMBER, metadata.lastSequenceNumber());\n    }\n    generator.writeNumberField(LAST_UPDATED_MILLIS, metadata.lastUpdatedMillis());\n    generator.writeNumberField(LAST_COLUMN_ID, metadata.lastColumnId());\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/TableMetadataParser.java#L142-L178","documentation":"This toJson overload renders TableMetadata to an in-memory String using a StringWriter/JsonGenerator. Although StringWriter never throws real IOExceptions, the Jackson generator API is checked, so failures are wrapped in RuntimeIOException ('Failed to write json for: <metadata>'). In practice this surfaces generator/serialization defects rather than environment problems.","triggerScenarios":"Calling TableMetadataParser.toJson(TableMetadata) when JSON generation fails — typically an unexpected internal state in TableMetadata handed to the generator (e.g. malformed nested values), or a bug in a toJson overload writing invalid structures.","commonSituations":"Debugging/dumping metadata to a string in tools or tests; custom catalogs that serialize metadata themselves; rarely hit in normal commits since string rendering is memory-only.","solutions":["Inspect the chained cause for the underlying generator failure","Verify the TableMetadata instance is well-formed (reload it from the catalog/metadata file)","Report upstream if a valid metadata object fails to serialize — likely a parser bug","As a workaround, round-trip via a file: write with TableMetadataParser.write then re-read"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { String json = TableMetadataParser.toJson(metadata); }\ncatch (RuntimeIOException e) {\n  LOG.error(\"In-memory metadata serialization failed: {}\", e.getCause(), e);\n}","preventionTips":["Treat this as a bug signal: in-memory JSON writing has no real I/O","Report upstream with the metadata object if a valid instance fails","Keep parser code (TableMetadataParser.toJson overloads) free of invalid writes","Prefer writing to a file for debugging to also surface real I/O conditions"],"tags":["json","serialization","runtime-io-exception","iceberg"],"backgroundTag":"json-serialization-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"}