apache/dolphinscheduler · error · IllegalArgumentException

bodyParams is not a valid json

Error message

bodyParams is not a valid json

What it means

The optional 'bodyParams' parameter, when non-blank, is parsed with JSONUtils.parseObject into Map<String,Object>; a null result means the string is not valid JSON, raising IllegalArgumentException('bodyParams 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:77

            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));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("requestType is not a valid value");
        }

        contentType = OkHttpRequestHeaderContentType.fromValue(paramsMap.get(HttpAlertConstants.NAME_CONTENT_TYPE));
        if (contentType == null) {
            throw new IllegalArgumentException("contentType is not a valid value");
        }

        timeout = (StringUtils.isNotBlank(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
                ? Integer.parseInt(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Provide bodyParams as a valid JSON object, e.g. {"key":"value"}.
  2. Validate the JSON before saving; remove bodyParams if a raw body is used elsewhere.
  3. Use double quotes for keys/strings inside the JSON object.

Example fix

// before
bodyParams=key1=value1&key2=value2
// after
bodyParams={"key1":"value1","key2":"value2"}
Defensive patterns

Strategy: validation

Validate before calling

String bp = paramsMap.get("bodyParams");
if (bp != null && !bp.isBlank()) { try { new com.fasterxml.jackson.databind.ObjectMapper().readValue(bp, Map.class); } catch (Exception e) { throw new IllegalArgumentException("bodyParams 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 bodyParams json", e); }

Prevention

When it happens

Trigger: bodyParams contains non-JSON text, a JSON array/scalar where an object is required, or trailing commas/invalid escapes.

Common situations: Sending form-style 'key=value&k2=v2' body instead of a JSON object; shell quoting mangling double quotes when saving params.

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/845dbf886889a927. Report an issue: GitHub.