{"record":{"id":"9b9baebe2ee39f94","repo":"apache/dolphinscheduler","slug":"environment-worker-groups-is-invalid","errorCode":"ENVIRONMENT_WORKER_GROUPS_IS_INVALID","errorMessage":"ENVIRONMENT_WORKER_GROUPS_IS_INVALID","messagePattern":"ENVIRONMENT_WORKER_GROUPS_IS_INVALID","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"warning","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java","lineNumber":433,"sourceCode":"                throw new ServiceException(Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR, workerGroup,\n                        environmentName, collect);\n            }\n        }\n    }\n\n    protected void checkParams(String name, String config, String workerGroups) {\n        if (StringUtils.isEmpty(name)) {\n            throw new ServiceException(Status.ENVIRONMENT_NAME_IS_NULL);\n        }\n        if (StringUtils.isEmpty(config)) {\n            throw new ServiceException(Status.ENVIRONMENT_CONFIG_IS_NULL);\n        }\n        if (StringUtils.isNotEmpty(workerGroups)) {\n            try {\n                JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {\n                });\n            } catch (IllegalArgumentException e) {\n                throw new ServiceException(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID);\n            }\n        }\n    }\n\n}\n","sourceCodeStart":415,"sourceCodeEnd":439,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java#L415-L439","documentation":"Thrown by checkParams when workerGroups is non-empty but is not valid JSON. checkParams attempts JSONUtils.parseObject into a List<String> and converts IllegalArgumentException into this error, so malformed worker group JSON is rejected early.","triggerScenarios":"Passing workerGroups like \"groupA\" or \"[groupA]\" (unquoted) instead of a JSON array such as \"[\\\"groupA\\\"]\" to createEnvironment or updateEnvironmentByCode.","commonSituations":"Shell scripts building JSON manually without quoting; copying workerGroups from logs with stripped escapes; UI bug sending a comma-separated string; passing a Java List's toString() output.","solutions":["Send a proper JSON array of strings, e.g. \\\"[\\\"groupA\\\"]\\\"","Escape quotes correctly when embedding in shell or JSON payloads","Use JSONUtils.toJsonString(list) (or equivalent) on the client instead of string concatenation","Validate the JSON payload with a linter before sending"],"exampleFix":"// before\nString workerGroups = \"[groupA, groupB]\"; // invalid JSON -> throws\n// after\nString workerGroups = \"[\\\"groupA\\\",\\\"groupB\\\"]\";","handlingStrategy":"validation","validationCode":"if (workerGroups != null && !workerGroups.isEmpty()) {\n    try {\n        JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {});\n    } catch (IllegalArgumentException e) {\n        throw new IllegalArgumentException(\"workerGroups must be a JSON array of strings\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    environmentService.createEnvironment(loginUser, name, desc, config, workerGroups);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID.getCode()) {\n        // fix JSON formatting and retry\n    } else { throw e; }\n}","preventionTips":["Always serialize worker group lists with a JSON library, never string concat","Validate payloads with a JSON parser before sending","Quote strings properly when building JSON in shell scripts"],"tags":["dolphinscheduler","environment","worker-group","json","malformed-input"],"backgroundTag":"json-parse-error","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}