{"record":{"id":"1d8a73c7b1f070f7","repo":"openzipkin/zipkin","slug":"s-reading-s-from-json","errorCode":null,"errorMessage":"%s reading %s from json","messagePattern":"(.+?) reading (.+?) from json","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"zipkin/src/main/java/zipkin2/internal/JsonCodec.java","lineNumber":221,"sourceCode":"\n  public static <T> void writeList(WriteBuffer.Writer<T> writer, List<T> value, WriteBuffer b) {\n    b.writeByte('[');\n    for (int i = 0, length = value.size(); i < length; ) {\n      writer.write(value.get(i++), b);\n      if (i < length) b.writeByte(',');\n    }\n    b.writeByte(']');\n  }\n\n  static IllegalArgumentException exceptionReading(String type, Exception e) {\n    String cause = e.getMessage() == null ? \"Error\" : e.getMessage();\n    if (cause.contains(\"Expected BEGIN_OBJECT\")\n      || cause.contains(\"Expected BEGIN_ARRAY\")\n      || cause.contains(\"malformed\")) {\n      cause = \"Malformed\";\n    }\n    String message = format(\"%s reading %s from json\", cause, type);\n    throw new IllegalArgumentException(message, e);\n  }\n}\n","sourceCodeStart":203,"sourceCodeEnd":224,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin/src/main/java/zipkin2/internal/JsonCodec.java#L203-L224","documentation":"Zipkin's JSON codec wraps every lower-level parse failure (from JsonReader) into an IllegalArgumentException whose message is '<cause> reading <type> from json'. The <type> names the Zipkin model object being decoded (e.g. 'List<Span>', 'Span', 'Endpoint'). Causes mentioning 'Expected BEGIN_OBJECT', 'Expected BEGIN_ARRAY', or 'malformed' are normalized to 'Malformed', so the message you see is usually 'Malformed reading List<Span> from json'. The original exception is preserved as the cause for full diagnostics.","triggerScenarios":"Calling SpanBytesDecoder.JSON_V2.decode(byte[]) (or decodeList) with bytes that are not valid JSON, are valid JSON of the wrong shape (e.g. an object where an array of spans is expected), contain malformed UTF-8, or are truncated mid-document. Also triggered by storage/transport layers (zipkin-server, kafka, rabbitmq collectors) decoding an incoming JSON body.","commonSituations":"A producer sends proto3 or thrift bytes to an endpoint configured for JSON; a truncated HTTP body is forwarded; a proxy re-encodes the payload wrongly; a version mismatch where V1 JSON is sent to a V2 JSON decoder.","solutions":["Inspect the original exception via getCause() (or the logged stack) to see the exact JSON token and offset that failed.","Verify the payload is actually JSON and matches the expected version: try decoding with SpanBytesDecoder.JSON_V1 vs JSON_V2, or PROTO3.","Validate the bytes externally (jq, json.tool) before re-sending; fix truncation at the producer/transport (Content-Length, max payload size).","If writing a collector, catch IllegalArgumentException per message and drop/quarantine the malformed span batch instead of killing the consumer."],"exampleFix":"// before\nList<Span> spans = SpanBytesDecoder.JSON_V2.decodeList(bytes);\n\n// after\nList<Span> spans;\ntry {\n  spans = SpanBytesDecoder.JSON_V2.decodeList(bytes);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Bad span payload: \" + new String(bytes, UTF_8), e);\n}","handlingStrategy":"try-catch","validationCode":"// no cheap pre-validation for arbitrary JSON; attempt decode and catch\nbyte[] bytes = ...;","typeGuard":null,"tryCatchPattern":"try { spans = SpanBytesDecoder.JSON_V2.decodeList(bytes); } catch (IllegalArgumentException e) { log.warn(\"bad span json: {}\", e.getMessage()); /* drop/quarantine */ }","preventionTips":["Pin one encoding (JSON_V2) across producers and collectors; set Content-Type explicitly.","Round-trip test encode/decode in CI for every pipeline component.","Never hand-build span JSON; use SpanBytesEncoder."],"tags":["zipkin","json","decoding","span"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}