wank125 opened a new issue, #18675:
URL: https://github.com/apache/dolphinscheduler/issues/18675

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   ### What happened
   
   When creating a workflow definition via the REST API (`POST 
/dolphinscheduler/projects/{projectCode}/process-definition`) with a 
`taskRelationJson` whose `preTaskCode` has no matching entry in 
`taskDefinitionJson`, the server hits a `NullPointerException` inside 
`ProcessServiceImpl#transformTask`:
   
   ```java
   
taskNode.setPreTasks(JSONUtils.toJsonString(code.getValue().stream().map(taskDefinitionLogMap::get)
           .map(TaskDefinition::getCode).collect(Collectors.toList())));
   ```
   
   `taskDefinitionLogMap::get` returns `null` for the unknown pre-task code, 
then `TaskDefinition::getCode` throws the NPE. The exception is swallowed by 
the generic `catch (Exception e)` in 
`WorkflowDefinitionServiceImpl#generateTaskRelationList` and the client only 
receives:
   
   ```json
   {"code": 10001, "msg": "request parameter taskRelationJson is not valid"}
   ```
   
   with no hint that the actual problem is a missing task definition.
   
   This is easy to hit when building the two JSON payloads programmatically 
(e.g. via the REST API instead of the UI): any code mismatch between 
`taskRelationJson` and `taskDefinitionJson` on a **pre** task silently degrades 
into the generic 10001 error.
   
   ### What you expected to happen
   
   The API should return the existing `TASK_DEFINE_NOT_EXIST` (50030) error 
naming the missing task code(s) — exactly what it already does for missing 
**post** task codes via the size-mismatch check in `generateTaskRelationList`. 
The pre-task codes simply never reach that check because the NPE happens first.
   
   ### How to reproduce
   
   1. Create a workflow definition through the REST API
   2. Send `taskRelationJson` = 
`[{"name":"","preTaskCode":123,"preTaskVersion":1,"postTaskCode":456,"postTaskVersion":1,"conditionType":0,"conditionParams":"{}"}]`
   3. Send `taskDefinitionJson` containing only the task with code `456` 
(nothing with code `123`)
   4. Response is the generic `10001` error; the server log shows the NPE stack 
trace at `ProcessServiceImpl.transformTask`
   
   ### Anything else
   
   The same method has two more null-unsafe spots:
   
   - `taskNode.setType(taskDefinitionLog.getTaskType().toUpperCase())` — NPE 
when `taskType` is null (reachable from other `transformTask` callers; the API 
path rejects it earlier)
   - `workflowTaskRelation.getPreTaskCode() != 0L` — unboxing NPE when the JSON 
omits `preTaskCode`
   
   ### Version
   
   3.2.2, and the same code is still present in the current `dev` branch.
   
   ### Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to