{"record":{"id":"d71e07a4de86321a","repo":"grpc/grpc-java","slug":"unsupported-version","errorCode":null,"errorMessage":"Unsupported version.","messagePattern":"Unsupported version\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"opentelemetry/src/main/java/io/grpc/opentelemetry/BinaryFormat.java","lineNumber":112,"sourceCode":"  public byte[] toBytes(SpanContext spanContext) {\n    checkNotNull(spanContext, \"spanContext\");\n    byte[] bytes = new byte[ALL_FORMAT_LENGTH];\n    bytes[VERSION_ID_OFFSET] = VERSION_ID;\n    bytes[TRACE_ID_FIELD_ID_OFFSET] = TRACE_ID_FIELD_ID;\n    System.arraycopy(spanContext.getTraceIdBytes(), 0, bytes, TRACE_ID_OFFSET, TRACE_ID_SIZE);\n    bytes[SPAN_ID_FIELD_ID_OFFSET] = SPAN_ID_FIELD_ID;\n    System.arraycopy(spanContext.getSpanIdBytes(), 0, bytes, SPAN_ID_OFFSET, SPAN_ID_SIZE);\n    bytes[TRACE_FLAG_FIELD_ID_OFFSET] = TRACE_FLAG_FIELD_ID;\n    bytes[TRACE_FLAG_OFFSET] = spanContext.getTraceFlags().asByte();\n    return bytes;\n  }\n\n\n  @Override\n  public SpanContext parseBytes(byte[] serialized) {\n    checkNotNull(serialized, \"bytes\");\n    if (serialized.length == 0 || serialized[0] != VERSION_ID) {\n      throw new IllegalArgumentException(\"Unsupported version.\");\n    }\n    if (serialized.length < REQUIRED_FORMAT_LENGTH) {\n      throw new IllegalArgumentException(\"Invalid input: truncated\");\n    }\n    String traceId;\n    String spanId;\n    TraceFlags traceFlags = TraceFlags.getDefault();\n    int pos = 1;\n    if (serialized[pos] == TRACE_ID_FIELD_ID) {\n      traceId = TraceId.fromBytes(\n          Arrays.copyOfRange(serialized, pos + ID_SIZE, pos + ID_SIZE + TRACE_ID_SIZE));\n      pos += ID_SIZE + TRACE_ID_SIZE;\n    } else {\n      throw new IllegalArgumentException(\"Invalid input: expected trace ID at offset \" + pos);\n    }\n    if (serialized[pos] == SPAN_ID_FIELD_ID) {\n      spanId = SpanId.fromBytes(\n          Arrays.copyOfRange(serialized, pos + ID_SIZE, pos + ID_SIZE + SPAN_ID_SIZE));","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/opentelemetry/src/main/java/io/grpc/opentelemetry/BinaryFormat.java#L94-L130","documentation":"BinaryFormat (the OpenTelemetry SpanContext propagator for gRPC) parses the binary propagation format, whose first byte must equal VERSION_ID. If the byte array is empty or starts with a different version byte, parseBytes throws IllegalArgumentException 'Unsupported version.'","triggerScenarios":"Passing a zero-length byte array or a binary blob serialized with an unknown/different version prefix into OpenTelemetryContextStorage/BinaryFormat.parseBytes (e.g. from another propagator's carrier).","commonSituations":"Cross-service tracing with mismatched propagation format versions, manual tests feeding arbitrary bytes, carriers populated by a different tracing system.","solutions":["Ensure the propagating side serializes with the same gRPC OpenTelemetry binary format (version byte 0 first)","Validate input length > 0 and serialized[0] == version before calling parseBytes","Align library versions between producer and consumer so the format matches"],"exampleFix":"// before\nSpanContext ctx = propagator.parseBytes(carrierBytes);\n// after\nif (carrierBytes != null && carrierBytes.length > 0 && carrierBytes[0] == 0) { SpanContext ctx = propagator.parseBytes(carrierBytes); }","handlingStrategy":"validation","validationCode":"boolean isParsableSpanContext(byte[] b) { return b != null && b.length > 0 && b[0] == 0; }","typeGuard":null,"tryCatchPattern":"try { ctx = propagator.parseBytes(bytes); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().equals(\"Unsupported version.\")) { /* fall back to default SpanContext */ ctx = SpanContext.INVALID; }\n}","preventionTips":["Use the library's toBytes()/parseBytes pair on both sides","Pin matching opentelemetry/gRPC library versions across services","Guard against empty carriers before parsing"],"tags":["grpc","opentelemetry","tracing","propagation","illegal-argument"],"backgroundTag":"unsupported-enum-value","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}