didi/DoKit · error · NullPointerException

name == null

Error message

name == null

What it means

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.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java:279

          i -= 2;
        }
      }
      return this;
    }

    /**
     * Set a field with the specified value. If the field is not found, it is added. If the field is
     * found, the existing values are replaced.
     */
    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));
        }
      }
    }

View on GitHub (pinned to 626827cddb)

Solutions

  1. Null-check and skip (or default) the name before add()/set()
  2. Fix the producer of the (name, value) pairs so names are always non-null strings
  3. Filter parsed pairs: if (name != null && value != null) builder.add(name, value)

Example fix

// before
for (String[] pair : parsedPairs) builder.add(pair[0], pair[1]);

// after
for (String[] pair : parsedPairs) {
  if (pair[0] != null && pair[1] != null) builder.add(pair[0], pair[1]);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (name != null && value != null) builder.add(name, value);

Type guard

boolean isValidHeaderName(String n) { return n != null && !n.isEmpty(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/a9e90c7035d2b913. Report an issue: GitHub.