didi/DoKit · error · NullPointerException
value == null
Error message
value == null
What it means
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.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java:288
*/
public Builder set(String name, String value) {
checkNameAndValue(name, value);
removeAll(name);
addLenient(name, value);
return this;
}
private void checkNameAndValue(String name, String value) {
if (name == null) throw new NullPointerException("name == null");
if (name.isEmpty()) throw new IllegalArgumentException("name is empty");
for (int i = 0, length = name.length(); i < length; i++) {
char c = name.charAt(i);
if (c <= '\u0020' || c >= '\u007f') {
throw new IllegalArgumentException(format(
"Unexpected char %#04x at %d in header name: %s", (int) c, i, name));
}
}
if (value == null) throw new NullPointerException("value == null");
for (int i = 0, length = value.length(); i < length; i++) {
char c = value.charAt(i);
if ((c <= '\u001f' && c != '\t') || c >= '\u007f') {
throw new IllegalArgumentException(format(
"Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value));
}
}
}
/** Equivalent to {@code build().get(name)}, but potentially faster. */
public String get(String name) {
for (int i = namesAndValues.size() - 2; i >= 0; i -= 2) {
if (name.equalsIgnoreCase(namesAndValues.get(i))) {
return namesAndValues.get(i + 1);
}
}
return null;
}View on GitHub (pinned to 626827cddb)
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
Example fix
// before
builder.add("Authorization", token); // token == null pre-login
// after
if (token != null) builder.add("Authorization", token); Defensive patterns
Strategy: type-guard
Validate before calling
if (value != null) builder.add(name, value); // else omit the header
Type guard
boolean isNonNullHeaderValue(String v) { return v != null; } Prevention
- Omit headers whose values are unavailable rather than adding null
- Resolve auth/session state before assembling headers in interceptors
When it happens
Trigger: 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.
Common situations: Auth tokens not yet available (pre-login requests); optional session values read from storage that return null; deserialized mock template headers with absent values.
Related errors
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/9b4e824554598948.
Report an issue: GitHub.