didi/DoKit · error · NullPointerException
namesAndValues == null
Error message
namesAndValues == null
What it means
Thrown by CommonHeaders.of(String... namesAndValues) when the varargs array is null. DoKit's CommonHeaders is a lightweight okhttp-Headers-style container used to snapshot request/response headers for the network inspector; the factory requires a non-null alternating name/value array.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java:161
}
return result;
}
private static String get(String[] namesAndValues, String name) {
for (int i = namesAndValues.length - 2; i >= 0; i -= 2) {
if (name.equalsIgnoreCase(namesAndValues[i])) {
return namesAndValues[i + 1];
}
}
return null;
}
/**
* Returns headers for the alternating header names and values. There must be an even number of
* arguments, and they must alternate between header names and values.
*/
public static CommonHeaders of(String... namesAndValues) {
if (namesAndValues == null) throw new NullPointerException("namesAndValues == null");
if (namesAndValues.length % 2 != 0) {
throw new IllegalArgumentException("Expected alternating header names and values");
}
// Make a defensive copy and clean it up.
namesAndValues = namesAndValues.clone();
for (int i = 0; i < namesAndValues.length; i++) {
if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null");
namesAndValues[i] = namesAndValues[i].trim();
}
// Check for malformed headers.
for (int i = 0; i < namesAndValues.length; i += 2) {
String name = namesAndValues[i];
String value = namesAndValues[i + 1];
if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) {
throw new IllegalArgumentException("Unexpected header: " + name + ": " + value);
}View on GitHub (pinned to 626827cddb)
Solutions
- Initialize the array before the call: CommonHeaders.of(new String[0]) for empty headers
- Fix the upstream code that produced the null array (usually an uninitialized or cleared header collection)
- Use the Builder API instead, which tolerates incremental construction
Example fix
// before
CommonHeaders h = CommonHeaders.of(headerArray); // headerArray == null
// after
CommonHeaders h = headerArray == null
? new CommonHeaders.Builder().build()
: CommonHeaders.of(headerArray); Defensive patterns
Strategy: type-guard
Validate before calling
String[] safe = (headerArray == null) ? new String[0] : headerArray; CommonHeaders h = CommonHeaders.of(safe);
Type guard
boolean isNonNullHeaderArray(String[] a) { return a != null; } Prevention
- Never forward raw arrays from interceptors without a null default
- Default to new String[0] or Builder for the empty case
When it happens
Trigger: Calling CommonHeaders.of((String[]) null) directly, or passing a null array variable such as a header array that was never initialized by an interceptor.
Common situations: Custom interceptors or mock servers forwarding a headers array that a previous stage failed to populate (e.g. a null responseHeaders array when building a mock network record).
Related errors
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/3a8cbc66c17aed90.
Report an issue: GitHub.