{"record":{"id":"9b4e824554598948","repo":"didi/DoKit","slug":"value-null","errorCode":null,"errorMessage":"value == null","messagePattern":"value == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java","lineNumber":288,"sourceCode":"     */\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\n    /** Equivalent to {@code build().get(name)}, but potentially faster. */\n    public String get(String name) {\n      for (int i = namesAndValues.size() - 2; i >= 0; i -= 2) {\n        if (name.equalsIgnoreCase(namesAndValues.get(i))) {\n          return namesAndValues.get(i + 1);\n        }\n      }\n      return null;\n    }","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java#L270-L306","documentation":"Thrown by CommonHeaders.Builder.checkNameAndValue when a header value is null. The name has already been validated by this point, so the message specifically pins the missing value.","triggerScenarios":"Calling builder.add(\"Authorization\", null) or set(name, null) — typically a token/cookie that has not been fetched yet when the interceptor builds the header snapshot.","commonSituations":"Auth tokens not yet available (pre-login requests); optional session values read from storage that return null; deserialized mock template headers with absent values.","solutions":["Skip the header entirely when the value is absent instead of adding null","Default to empty string if the header must be present: builder.add(name, value == null ? \"\" : value)","Ensure login-state is resolved before headers are assembled in the interceptor chain"],"exampleFix":"// before\nbuilder.add(\"Authorization\", token); // token == null pre-login\n\n// after\nif (token != null) builder.add(\"Authorization\", token);","handlingStrategy":"type-guard","validationCode":"if (value != null) builder.add(name, value); // else omit the header","typeGuard":"boolean isNonNullHeaderValue(String v) { return v != null; }","tryCatchPattern":null,"preventionTips":["Omit headers whose values are unavailable rather than adding null","Resolve auth/session state before assembling headers in interceptors"],"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"}