{"record":{"id":"a9e90c7035d2b913","repo":"didi/DoKit","slug":"name-null","errorCode":null,"errorMessage":"name == null","messagePattern":"name == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java","lineNumber":279,"sourceCode":"          i -= 2;\n        }\n      }\n      return this;\n    }\n\n    /**\n     * Set a field with the specified value. If the field is not found, it is added. If the field is\n     * found, the existing values are replaced.\n     */\n    public Builder set(String name, String value) {\n      checkNameAndValue(name, value);\n      removeAll(name);\n      addLenient(name, value);\n      return this;\n    }\n\n    private void checkNameAndValue(String name, String value) {\n      if (name == null) throw new NullPointerException(\"name == null\");\n      if (name.isEmpty()) throw new IllegalArgumentException(\"name is empty\");\n      for (int i = 0, length = name.length(); i < length; i++) {\n        char c = name.charAt(i);\n        if (c <= '\\u0020' || c >= '\\u007f') {\n          throw new IllegalArgumentException(format(\n              \"Unexpected char %#04x at %d in header name: %s\", (int) c, i, name));\n        }\n      }\n      if (value == null) throw new NullPointerException(\"value == null\");\n      for (int i = 0, length = value.length(); i < length; i++) {\n        char c = value.charAt(i);\n        if ((c <= '\\u001f' && c != '\\t') || c >= '\\u007f') {\n          throw new IllegalArgumentException(format(\n              \"Unexpected char %#04x at %d in %s value: %s\", (int) c, i, name, value));\n        }\n      }\n    }\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java#L261-L297","documentation":"Thrown by CommonHeaders.Builder.checkNameAndValue when a header name is null. checkNameAndValue runs for every add(name, value)/set(name, value) call and enforces okhttp-grade name validation before the pair is stored.","triggerScenarios":"Calling builder.add(null, \"gzip\") or set(null, value) — e.g. a header name taken from a parsed structure where the name slot was never populated.","commonSituations":"Looping over parsed or deserialized header pairs where a malformed entry has a null key; forwarding a name extracted with substring() from a line without a colon (which yields unexpected nulls in custom parsers).","solutions":["Null-check and skip (or default) the name before add()/set()","Fix the producer of the (name, value) pairs so names are always non-null strings","Filter parsed pairs: if (name != null && value != null) builder.add(name, value)"],"exampleFix":"// before\nfor (String[] pair : parsedPairs) builder.add(pair[0], pair[1]);\n\n// after\nfor (String[] pair : parsedPairs) {\n  if (pair[0] != null && pair[1] != null) builder.add(pair[0], pair[1]);\n}","handlingStrategy":"type-guard","validationCode":"if (name != null && value != null) builder.add(name, value);","typeGuard":"boolean isValidHeaderName(String n) { return n != null && !n.isEmpty(); }","tryCatchPattern":null,"preventionTips":["Never call add/set with a possibly-null name; skip or default first","Filter parsed (name, value) pairs through a null check before the loop body"],"tags":["android","network","headers","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}