{"record":{"id":"638700c27d67a6dd","repo":"quarkusio/quarkus","slug":"cannot-remove-header-key-must-not-be-null","errorCode":null,"errorMessage":"Cannot remove header, key must not be null","messagePattern":"Cannot remove header, key must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/mailer/runtime/src/main/java/io/quarkus/mailer/Mail.java","lineNumber":333,"sourceCode":"     */\n    public Mail addHeader(String key, String... values) {\n        if (key == null || values == null) {\n            throw new IllegalArgumentException(\"Cannot add header, key and value must not be null\");\n        }\n        List<String> content = this.headers.computeIfAbsent(key, k -> new ArrayList<>());\n        Collections.addAll(content, values);\n        return this;\n    }\n\n    /**\n     * Removes a header.\n     *\n     * @param key the header name, must not be {@code null}.\n     * @return the current {@link Mail}\n     */\n    public Mail removeHeader(String key) {\n        if (key == null) {\n            throw new IllegalArgumentException(\"Cannot remove header, key must not be null\");\n        }\n        headers.remove(key);\n        return this;\n    }\n\n    /**\n     * Sets the list of headers.\n     *\n     * @param headers the headers\n     * @return the current {@link Mail}\n     */\n    public Mail setHeaders(Map<String, List<String>> headers) {\n        this.headers = Objects.requireNonNullElseGet(headers, HashMap::new);\n        return this;\n    }\n\n    /**\n     * Adds an inline attachment.","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/Mail.java#L315-L351","documentation":"Mail.removeHeader(key) rejects a null header name with IllegalArgumentException. It is a public API guard; the method then simply removes the (possibly absent) key from the headers map, so a non-null key that does not exist is not an error.","triggerScenarios":"Calling mail.removeHeader(null), usually because the header name came from a variable, map lookup, or optional field that was null.","commonSituations":"Removing a conditional header based on user input or configuration where the name resolves to null; generic header-manipulation helper methods that don't pre-check names.","solutions":["Check the header name for null before calling removeHeader","Skip the call when the name is null/blank","Ensure the source of the header name (config, map, request attribute) is populated"],"exampleFix":"// before\nmail.removeHeader(configuredHeaderName); // null when not configured\n// after\nif (configuredHeaderName != null) {\n    mail.removeHeader(configuredHeaderName);\n}","handlingStrategy":"validation","validationCode":"if (key != null) {\n    mail.removeHeader(key);\n}","typeGuard":"boolean isRemovableHeader(String key) {\n    return key != null && !key.isBlank();\n}","tryCatchPattern":"try {\n    mail.removeHeader(key);\n} catch (IllegalArgumentException e) {\n    log.warnf(\"Ignoring null header name on remove\");\n}","preventionTips":["Guard variable header names before removal calls","Treat removeHeader of a non-null absent key as safe — it's a no-op, no existence check needed","Centralize header manipulation so null checks live in one place"],"tags":["quarkus","mailer","validation","null-check"],"backgroundTag":"null-argument-rejected","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}