{"record":{"id":"0f9ff01d68271eb9","repo":"didi/DoKit","slug":"field-null","errorCode":null,"errorMessage":"field == null","messagePattern":"field == null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java","lineNumber":688,"sourceCode":"        }\n\n        @Override\n        public String getResponseMessage() throws IOException {\n            return getResponse(true).message();\n        }\n\n        @Override\n        public int getResponseCode() throws IOException {\n            return getResponse(true).code();\n        }\n\n        @Override\n        public void setRequestProperty(String field, String newValue) {\n            if (connected) {\n                throw new IllegalStateException(\"Cannot set request property after connection is made\");\n            }\n            if (field == null) {\n                throw new NullPointerException(\"field == null\");\n            }\n            if (newValue == null) {\n                return;\n            }\n\n            requestHeaders.set(field, newValue);\n        }\n\n        @Override\n        public void setIfModifiedSince(long newValue) {\n            super.setIfModifiedSince(newValue);\n            if (ifModifiedSince != 0) {\n                requestHeaders.set(\"If-Modified-Since\", format(new Date(ifModifiedSince)));\n            } else {\n                requestHeaders.removeAll(\"If-Modified-Since\");\n            }\n        }\n","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java#L670-L706","documentation":"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.","triggerScenarios":"Calling setRequestProperty(null, value), typically because the header name came from a map entry, config key, or variable that is null.","commonSituations":"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.","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)."],"exampleFix":"// before\nfor (Map.Entry<String,String> e : headers.entrySet()) {\n  conn.setRequestProperty(e.getKey(), e.getValue()); // key null -> NPE\n}\n\n// after\nfor (Map.Entry<String,String> e : headers.entrySet()) {\n  if (e.getKey() != null) conn.setRequestProperty(e.getKey(), e.getValue());\n}","handlingStrategy":"validation","validationCode":"if (field != null && !field.trim().isEmpty()) conn.setRequestProperty(field, value);","typeGuard":"static boolean isValidHeaderName(String s) { return s != null && !s.isEmpty() && s.indexOf(':') < 0; }","tryCatchPattern":null,"preventionTips":["Filter null keys out of header maps before iterating.","Derive header names from constants, not from dynamic/config strings."],"tags":["network","http","headers","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}