didi/DoKit · error · NullPointerException
field == null
Error message
field == null
What it means
setRequestProperty() rejects a null header name with NullPointerException("field == null") per the HttpURLConnection API contract; the check runs after the connected check but before the value null-check (a null value is silently ignored instead). Any header key derived from a nullable source can trip this.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java:688
}
@Override
public String getResponseMessage() throws IOException {
return getResponse(true).message();
}
@Override
public int getResponseCode() throws IOException {
return getResponse(true).code();
}
@Override
public void setRequestProperty(String field, String newValue) {
if (connected) {
throw new IllegalStateException("Cannot set request property after connection is made");
}
if (field == null) {
throw new NullPointerException("field == null");
}
if (newValue == null) {
return;
}
requestHeaders.set(field, newValue);
}
@Override
public void setIfModifiedSince(long newValue) {
super.setIfModifiedSince(newValue);
if (ifModifiedSince != 0) {
requestHeaders.set("If-Modified-Since", format(new Date(ifModifiedSince)));
} else {
requestHeaders.removeAll("If-Modified-Since");
}
}
View on GitHub (pinned to 626827cddb)
Solutions
- Null- or blank-check header names before calling setRequestProperty.
- Filter null keys when building the header map: headers.keySet().removeIf(Objects::isNull).
- Fix the upstream producer of the null header name (config or model field).
Example fix
// before
for (Map.Entry<String,String> e : headers.entrySet()) {
conn.setRequestProperty(e.getKey(), e.getValue()); // key null -> NPE
}
// after
for (Map.Entry<String,String> e : headers.entrySet()) {
if (e.getKey() != null) conn.setRequestProperty(e.getKey(), e.getValue());
} Defensive patterns
Strategy: validation
Validate before calling
if (field != null && !field.trim().isEmpty()) conn.setRequestProperty(field, value);
Type guard
static boolean isValidHeaderName(String s) { return s != null && !s.isEmpty() && s.indexOf(':') < 0; } Prevention
- Filter null keys out of header maps before iterating.
- Derive header names from constants, not from dynamic/config strings.
When it happens
Trigger: Calling setRequestProperty(null, value), typically because the header name came from a map entry, config key, or variable that is null.
Common situations: Iterating a Map<String,String> of headers where a key is null; building header names from string concatenation or config lookups that can return null.
Related errors
- Cannot add request property after connection is made
- namesAndValues == null
- Headers cannot be null
- headers == null
- name == null
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/0f9ff01d68271eb9.
Report an issue: GitHub.