{"record":{"id":"9fa883b4d4df62fa","repo":"didi/DoKit","slug":"headers-null","errorCode":null,"errorMessage":"headers == null","messagePattern":"headers == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java","lineNumber":189,"sourceCode":"    }\n\n    // Check for malformed headers.\n    for (int i = 0; i < namesAndValues.length; i += 2) {\n      String name = namesAndValues[i];\n      String value = namesAndValues[i + 1];\n      if (name.length() == 0 || name.indexOf('\\0') != -1 || value.indexOf('\\0') != -1) {\n        throw new IllegalArgumentException(\"Unexpected header: \" + name + \": \" + value);\n      }\n    }\n\n    return new CommonHeaders(namesAndValues);\n  }\n\n  /**\n   * Returns headers for the header names and values in the {@link Map}.\n   */\n  public static CommonHeaders of(Map<String, String> headers) {\n    if (headers == null) throw new NullPointerException(\"headers == null\");\n\n    // Make a defensive copy and clean it up.\n    String[] namesAndValues = new String[headers.size() * 2];\n    int i = 0;\n    for (Map.Entry<String, String> header : headers.entrySet()) {\n      if (header.getKey() == null || header.getValue() == null) {\n        throw new IllegalArgumentException(\"Headers cannot be null\");\n      }\n      String name = header.getKey().trim();\n      String value = header.getValue().trim();\n      if (name.length() == 0 || name.indexOf('\\0') != -1 || value.indexOf('\\0') != -1) {\n        throw new IllegalArgumentException(\"Unexpected header: \" + name + \": \" + value);\n      }\n      namesAndValues[i] = name;\n      namesAndValues[i + 1] = value;\n      i += 2;\n    }\n","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/common/CommonHeaders.java#L171-L207","documentation":"Thrown by the Map overload CommonHeaders.of(Map<String, String> headers) when the passed map is null. This factory flattens the map into the internal name/value array, so a non-null map is a hard precondition.","triggerScenarios":"Calling CommonHeaders.of((Map<String, String>) null), e.g. forwarding request.headers plus a nullable extra-headers map that was never defaulted.","commonSituations":"Optional request extras (extra headers map from a mock template or config) that are null by default and are forwarded without a null check.","solutions":["Default the map: of(map == null ? Collections.emptyMap() : map)","Use CommonHeaders.EMPTY-style empty Builder result when no headers are needed","Fix the config layer to always supply a non-null (possibly empty) map"],"exampleFix":"// before\nCommonHeaders h = CommonHeaders.of(extraHeaders); // extraHeaders == null by default\n\n// after\nCommonHeaders h = CommonHeaders.of(extraHeaders != null ? extraHeaders : new HashMap<String, String>());","handlingStrategy":"type-guard","validationCode":"Map<String, String> safe = (headersMap == null) ? new LinkedHashMap<String, String>() : headersMap;\nCommonHeaders h = CommonHeaders.of(safe);","typeGuard":"boolean isNonNullHeaderMap(Map<String, String> m) { return m != null; }","tryCatchPattern":null,"preventionTips":["Default optional header maps to empty maps at the config layer","Treat 'no extra headers' as emptyMap(), never null"],"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"}