{"record":{"id":"8e55b05e245d82d0","repo":"openzipkin/zipkin","slug":"key-null-8e55b0","errorCode":null,"errorMessage":"key == null","messagePattern":"key == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"zipkin/src/main/java/zipkin2/Span.java","lineNumber":537,"sourceCode":"\n    /** Sets {@link Span#annotations} */\n    public Builder addAnnotation(long timestamp, String value) {\n      if (annotations == null) annotations = new ArrayList<>(2);\n      annotations.add(Annotation.create(timestamp, value));\n      return this;\n    }\n\n    /** Sets {@link Span#annotations} */\n    public Builder clearAnnotations() {\n      if (annotations == null) return this;\n      annotations.clear();\n      return this;\n    }\n\n    /** Sets {@link Span#tags} */\n    public Builder putTag(String key, String value) {\n      if (tags == null) tags = new TreeMap<>();\n      if (key == null) throw new NullPointerException(\"key == null\");\n      if (value == null) throw new NullPointerException(\"value of \" + key + \" == null\");\n      this.tags.put(key, value);\n      return this;\n    }\n\n    /** Sets {@link Span#tags} */\n    public Builder clearTags() {\n      if (tags == null) return this;\n      tags.clear();\n      return this;\n    }\n\n    /** Sets {@link Span#debug} */\n    public Builder debug(boolean debug) {\n      flags |= FLAG_DEBUG_SET;\n      if (debug) {\n        flags |= FLAG_DEBUG;\n      } else {","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin/src/main/java/zipkin2/Span.java#L519-L555","documentation":"Span.Builder.putTag(String key, String value) throws NullPointerException when key is null ('key == null'), and a second NPE with message 'value of <key> == null' for a null value. Tags are stored in a TreeMap keyed by string, so null keys would break sorting and serialization. Both arguments are always required.","triggerScenarios":"Calling putTag(null, \"v\"), putTag(k, map.get(missingKey)), or looping over a Map<String,String> that legitimately contains null keys/values (e.g. from JSON parsing or JDBC result maps).","commonSituations":"Tagging loops over request headers, system properties, or ORM rows where null values are legal in the source map; conditional tagging code where the key is built from optional request fields (e.g. \"http.path\" from a null URI).","solutions":["Filter null keys and values before putting: if (k != null && v != null) b.putTag(k, v).","Convert null values to a sentinel string (\"null\" or \"\") if you want to record the field's absence explicitly.","Where the null originates from optional request state, skip tagging that attribute entirely."],"exampleFix":"// before\nfor (Map.Entry<String,String> e : attributes.entrySet()) {\n  b.putTag(e.getKey(), e.getValue());\n}\n\n// after\nfor (Map.Entry<String,String> e : attributes.entrySet()) {\n  if (e.getKey() != null && e.getValue() != null) b.putTag(e.getKey(), e.getValue());\n}","handlingStrategy":"validation","validationCode":"for (Map.Entry<String,String> e : attrs.entrySet()) {\n  if (e.getKey() != null && e.getValue() != null) b.putTag(e.getKey(), e.getValue());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter null keys/values in tag loops over headers, properties, and row maps.","Use a single safePutTag(builder, key, value) helper across the codebase."],"tags":["zipkin","span","tags","null-pointer","builder"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}