{"record":{"id":"0311941f8aee2424","repo":"openzipkin/zipkin","slug":"end-of-input-while-parsing-object","errorCode":null,"errorMessage":"End of input while parsing object.","messagePattern":"End of input while parsing object\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"zipkin-storage/elasticsearch/src/main/java/zipkin2/elasticsearch/internal/JsonSerializers.java","lineNumber":53,"sourceCode":"\n  public interface ObjectParser<T> {\n    T parse(JsonParser jsonParser) throws IOException;\n  }\n\n  public static final ObjectParser<Span> SPAN_PARSER = JsonSerializers::parseSpan;\n\n  static Span parseSpan(JsonParser parser) throws IOException {\n    if (!parser.isExpectedStartObjectToken()) {\n      throw new IllegalArgumentException(\"Not a valid JSON object, start token: \" +\n        parser.currentToken());\n    }\n\n    Span.Builder result = Span.newBuilder();\n\n    JsonToken value;\n    while ((value = parser.nextValue()) != JsonToken.END_OBJECT) {\n      if (value == null) {\n        throw new IOException(\"End of input while parsing object.\");\n      }\n      if (value == JsonToken.VALUE_NULL) {\n        continue;\n      }\n      switch (parser.currentName()) {\n        case \"traceId\":\n          result.traceId(parser.getText());\n          break;\n        case \"parentId\":\n          result.parentId(parser.getText());\n          break;\n        case \"id\":\n          result.id(parser.getText());\n          break;\n        case \"kind\":\n          result.kind(Span.Kind.valueOf(parser.getText()));\n          break;\n        case \"name\":","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-storage/elasticsearch/src/main/java/zipkin2/elasticsearch/internal/JsonSerializers.java#L35-L71","documentation":"While iterating a span object's fields with parser.nextValue(), a null token means the input ended before the closing '}' — truncated JSON. The parser throws IOException('End of input while parsing object.') rather than silently returning a half-built span, so incomplete data never masquerades as a valid span.","triggerScenarios":"Feeding SPAN_PARSER a truncated document such as {\"traceId\":\"abc\" (no closing brace); streaming spans from a source that cuts off mid-record; decompression or transfer truncating Elasticsearch response bodies.","commonSituations":"Reading span JSON from files/message queues where records were split; HTTP responses truncated by proxies with response-size limits; hand-built test fixtures missing braces.","solutions":["Validate the JSON is complete before parsing (matching braces / json.Parse up front, or lenient read of full content first).","Fix the transport producing truncation (proxy buffer limits, message framing).","Regenerate or repair the malformed fixtures/records at their source."],"exampleFix":"// before\nString json = \"{\\\"traceId\\\":\\\"abc\\\"\";  // missing '}'\nSPAN_PARSER.parse(factory.createParser(json)); // IOException: End of input while parsing object.\n\n// after\nString json = \"{\\\"traceId\\\":\\\"abc\\\",\\\"id\\\":\\\"def\\\"}\";\nSpan span = SPAN_PARSER.parse(factory.createParser(json));","handlingStrategy":"validation","validationCode":"// ensure the document is complete JSON before handing it to the span parser\nvar node = objectMapper.readTree(spanJson); // throws on truncated input with a clear error\nif (node == null || !node.isObject()) throw new IOException(\"Incomplete span payload\");","typeGuard":null,"tryCatchPattern":"try {\n  Span span = SPAN_PARSER.parse(factory.createParser(json));\n} catch (IOException e) {\n  if (\"End of input while parsing object.\".equals(e.getMessage())) {\n    // truncated record: log, drop, and alert on the transport doing the truncation\n  }\n}","preventionTips":["Parse from complete buffered strings, not partial streams, when provenance is uncertain.","Fix proxy/queue framing limits that truncate response bodies.","Add end-to-end checksums or length prefixes when shipping span JSON through queues."],"tags":["elasticsearch","json-parsing","truncated-input","span","deserialization"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}