{"record":{"id":"dd45558aeb3ae178","repo":"openzipkin/zipkin","slug":"empty-id","errorCode":null,"errorMessage":"empty id","messagePattern":"empty id","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"zipkin/src/main/java/zipkin2/Span.java","lineNumber":448,"sourceCode":"        return this;\n      }\n      int length = parentId.length();\n      if (length == 0) throw new IllegalArgumentException(\"parentId is empty\");\n      if (length > 16) throw new IllegalArgumentException(\"parentId.length > 16\");\n      if (validateHexAndReturnZeroPrefix(parentId) == length) {\n        this.parentId = null;\n      } else {\n        this.parentId = length < 16 ? padLeft(parentId, 16) : parentId;\n      }\n      return this;\n    }\n\n    /**\n     * Hex encodes the input as the {@link Span#id()} or throws IllegalArgumentException if the\n     * input is zero.\n     */\n    public Builder id(long id) {\n      if (id == 0L) throw new IllegalArgumentException(\"empty id\");\n      this.id = toLowerHex(id);\n      return this;\n    }\n\n    /** Sets {@link Span#id()} or throws {@link IllegalArgumentException} if not lower-hex format. */\n    public Builder id(String id) {\n      if (id == null) throw new NullPointerException(\"id == null\");\n      int length = id.length();\n      if (length == 0) throw new IllegalArgumentException(\"id is empty\");\n      if (length > 16) throw new IllegalArgumentException(\"id.length > 16\");\n      if (validateHexAndReturnZeroPrefix(id) == 16) {\n        throw new IllegalArgumentException(\"id is all zeros\");\n      }\n      this.id = length < 16 ? padLeft(id, 16) : id;\n      return this;\n    }\n\n    /** Sets {@link Span#kind} */","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin/src/main/java/zipkin2/Span.java#L430-L466","documentation":"Span.Builder.id(long id) hex-encodes a 64-bit span ID and throws IllegalArgumentException('empty id') when the value is 0L. A span ID of zero is reserved/invalid in the Zipkin model, exactly like an all-zero hex ID. Every span must have a non-zero ID so it can be uniquely referenced as a parent by child spans.","triggerScenarios":"Calling .id(0L) directly, or passing a long that was never assigned because the ID source (MDC, context, random generator result assigned conditionally) was missing.","commonSituations":"Custom instrumentation that generates span IDs with new Random().nextLong() and forgets that nextLong() can return 0 (rare but real), or code paths that read a span ID from a context object that was not initialized for this request.","solutions":["Ensure the ID is generated with a non-zero generator (e.g. ThreadLocalRandom.current().nextLong() retried on 0, or the tracer's built-in ID generator).","If the ID genuinely may be absent, skip creating the span instead of defaulting the long to 0.","If you hold the ID as a hex string, use .id(String) which validates the hex form directly."],"exampleFix":"// before\nlong spanId = context.spanId(); // may be 0 when absent\nb.id(spanId);\n\n// after\nlong spanId = context.spanId();\nif (spanId == 0L) spanId = ThreadLocalRandom.current().nextLong();\nb.id(spanId);","handlingStrategy":"validation","validationCode":"long nonZeroSpanId(long candidate) {\n  return candidate != 0L ? candidate : ThreadLocalRandom.current().nextLong();\n}\n// b.id(nonZeroSpanId(ctx.spanId()));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the tracer's ID generator instead of raw Random.","Never use a primitive long default of 0 as a stand-in for a missing span ID."],"tags":["zipkin","span","span-id","validation","builder"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}