{"record":{"id":"b65d8750719e29aa","repo":"apache/iceberg","slug":"failed-to-read-streamingoffset-from-json-b65d87","errorCode":null,"errorMessage":"Failed to read StreamingOffset from json","messagePattern":"Failed to read StreamingOffset from json","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StreamingOffset.java","lineNumber":80,"sourceCode":"    Preconditions.checkNotNull(json, \"Cannot parse StreamingOffset JSON: null\");\n\n    try {\n      JsonNode node = JsonUtil.mapper().readValue(json, JsonNode.class);\n      return fromJsonNode(node);\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          String.format(\"Failed to parse StreamingOffset from JSON string %s\", json), e);\n    }\n  }\n\n  static StreamingOffset fromJson(InputStream inputStream) {\n    Preconditions.checkNotNull(inputStream, \"Cannot parse StreamingOffset from inputStream: null\");\n\n    JsonNode node;\n    try {\n      node = JsonUtil.mapper().readValue(inputStream, JsonNode.class);\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to read StreamingOffset from json\", e);\n    }\n\n    return fromJsonNode(node);\n  }\n\n  @Override\n  public String json() {\n    StringWriter writer = new StringWriter();\n    try (JsonGenerator generator = JsonUtil.factory().createGenerator(writer)) {\n      generator.writeStartObject();\n      generator.writeNumberField(VERSION, CURR_VERSION);\n      generator.writeNumberField(SNAPSHOT_ID, snapshotId);\n      generator.writeNumberField(POSITION, position);\n      generator.writeBooleanField(SCAN_ALL_FILES, scanAllFiles);\n      generator.writeEndObject();\n      generator.flush();\n\n    } catch (IOException e) {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StreamingOffset.java#L62-L98","documentation":"StreamingOffset.fromJson(InputStream) reads JSON from a stream and parses it into a StreamingOffset. Any IOException during reading the stream is wrapped in UncheckedIOException with this generic message and the original cause attached.","triggerScenarios":"Supplying a closed, unreadable, or failing InputStream to StreamingOffset.fromJson(InputStream), e.g. a truncated checkpoint offset file.","commonSituations":"Reading offsets from corrupted checkpoint storage (HDFS/S3 failures); file truncated mid-write; permission errors opening the offset stream.","solutions":["Check the wrapped cause for the underlying I/O failure (permissions, network, truncation)","Repair or restore the checkpoint offset file from backup","Ensure the stream is fully readable and not closed before parsing","Restart the streaming query with a valid checkpoint if the offset cannot be recovered"],"exampleFix":"// before\ntry (InputStream in = new FileInputStream(maybeMissingOffsetFile)) {\n  offset = StreamingOffset.fromJson(in);\n}\n// after\nif (!offsetFile.exists()) {\n  offset = StreamingOffset.START_OFFSET;\n} else {\n  try (InputStream in = new FileInputStream(offsetFile)) {\n    offset = StreamingOffset.fromJson(in);\n  }\n}","handlingStrategy":"try-catch","validationCode":"if (inputStream == null || inputStream.available() <= 0) {\n  return StreamingOffset.START_OFFSET;\n}","typeGuard":null,"tryCatchPattern":"try {\n  offset = StreamingOffset.fromJson(in);\n} catch (UncheckedIOException e) {\n  LOG.warn(\"Unreadable offset stream, resetting\", e);\n  offset = StreamingOffset.START_OFFSET;\n}","preventionTips":["Verify checkpoint storage health (permissions, network) before reading offsets","Always read offsets inside try-with-resources","Treat empty/missing offset files as a fresh start rather than a hard failure"],"tags":["file-read-failed","json","spark","streaming"],"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"}