apache/dolphinscheduler · error · IllegalArgumentException

headerParams is not a valid json

Error message

headerParams is not a valid json

What it means

If the optional 'headerParams' parameter is non-blank, HttpSender parses it with JSONUtils.toMap; a null result (malformed JSON or JSON that is not an object) triggers IllegalArgumentException('headerParams is not a valid json').

Source

Thrown at dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java:66

    private HttpRequestMethod requestType;
    private int timeout;
    private String url;

    HttpSender(Map<String, String> paramsMap) {
        paramsValidator(paramsMap);
    }

    private void paramsValidator(Map<String, String> paramsMap) {
        url = paramsMap.get(HttpAlertConstants.NAME_URL);
        if (StringUtils.isBlank(url)) {
            throw new IllegalArgumentException("url can not be null");
        }

        String headerParamsString = paramsMap.get(HttpAlertConstants.NAME_HEADER_PARAMS);
        if (StringUtils.isNotBlank(headerParamsString)) {
            headerParams = JSONUtils.toMap(headerParamsString);
            if (headerParams == null) {
                throw new IllegalArgumentException("headerParams is not a valid json");
            }
        } else {
            headerParams = new HashMap<>();
        }

        String bodyParamsString = paramsMap.get(HttpAlertConstants.NAME_BODY_PARAMS);
        if (StringUtils.isNotBlank(bodyParamsString)) {
            bodyParams = JSONUtils.parseObject(bodyParamsString, new TypeReference<Map<String, Object>>() {
            });
            if (bodyParams == null) {
                throw new IllegalArgumentException("bodyParams is not a valid json");
            }
        } else {
            bodyParams = new HashMap<>();
        }

        try {
            requestType = HttpRequestMethod.valueOf(paramsMap.get(HttpAlertConstants.NAME_REQUEST_TYPE));

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Set headerParams to a valid JSON object, e.g. {"Authorization":"Bearer token"}.
  2. Validate the JSON (e.g. JSON.parse) before saving the alert params.
  3. Remove headerParams entirely if no custom headers are needed (defaults to empty map).

Example fix

// before
headerParams=Authorization: Bearer xyz
// after
headerParams={"Authorization":"Bearer xyz"}
Defensive patterns

Strategy: validation

Validate before calling

String hp = paramsMap.get("headerParams");
if (hp != null && !hp.isBlank()) { try { new com.fasterxml.jackson.databind.ObjectMapper().readValue(hp, Map.class); } catch (Exception e) { throw new IllegalArgumentException("headerParams must be a JSON object"); } }

Type guard

boolean isJsonObject(String s) { if (s == null) return true; try { return JSONUtils.parseObject(s, new TypeReference<Map<String,Object>>(){}) != null; } catch (Exception e) { return false; } }

Try / catch

try { new HttpAlert(paramsMap); } catch (IllegalArgumentException e) { log.error("invalid headerParams json", e); }

Prevention

When it happens

Trigger: headerParams set to non-JSON text, a JSON array, or a scalar, e.g. 'a=1' or '[{"k":"v"}]'.

Common situations: User pastes curl-style '-H "k: v"' header syntax instead of a JSON object; quotes stripped by a shell/UI when saving the alert instance.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/4374131af625c3ef. Report an issue: GitHub.