wank125 opened a new pull request, #18676:
URL: https://github.com/apache/dolphinscheduler/pull/18676

   ## Was this PR generated or assisted by AI?
   
   YES — the fix, the unit test and this description were drafted with AI 
assistance (Claude-based coding agent); the bug itself was discovered while 
driving the DolphinScheduler 3.2.2 REST API from a data-sync pipeline. The 
change was reviewed, compiled and tested locally by the submitter.
   
   ## Purpose of the pull request
   
   Fixes #18675
   
   When `taskRelationJson` references a task code that has no matching entry in 
`taskDefinitionJson`, `ProcessServiceImpl#transformTask` throws a 
`NullPointerException`:
   
   ```java
   
taskNode.setPreTasks(JSONUtils.toJsonString(code.getValue().stream().map(taskDefinitionLogMap::get)
           .map(TaskDefinition::getCode).collect(Collectors.toList())));
   ```
   
   The NPE is caught by the generic `catch (Exception e)` in 
`WorkflowDefinitionServiceImpl#generateTaskRelationList` and returned to the 
client as a generic `10001 REQUEST_PARAMS_NOT_VALID_ERROR` with no hint about 
the real cause. This is easy to hit when building the two JSON payloads 
programmatically (REST API instead of the UI): any code mismatch between the 
relations and the definitions on a **pre** task silently degrades into the 
generic error.
   
   The existing size-mismatch check in `generateTaskRelationList` already 
returns `TASK_DEFINE_NOT_EXIST` for missing **post** task codes, but pre-task 
codes never reach it — the NPE happens first.
   
   ## Brief change log
   
   - `WorkflowDefinitionServiceImpl#generateTaskRelationList`: before calling 
`transformTask`, validate that every pre/post task code referenced by the 
relations has a matching task definition; throw `TASK_DEFINE_NOT_EXIST` (50030) 
naming the missing codes — the same semantics the existing post-code check 
already uses. This covers both the create and the update path.
   - `ProcessServiceImpl#transformTask`: make the mapping null-safe 
(`filter(Objects::nonNull)` on the pre-task lookup, null-safe `taskType`) so 
that other callers of this service method degrade gracefully instead of 
throwing NPE.
   
   ## Verify this pull request
   
   This change added tests and can be verified as follows:
   
   - Added `testCreateWorkflowDefinitionShouldRejectUnknownPreTaskCode` to 
`WorkflowDefinitionServiceTest`: a relation referencing an unknown 
`preTaskCode` now fails fast with `TASK_DEFINE_NOT_EXIST` and nothing is 
persisted.
   - Ran `mvn -pl dolphinscheduler-api -am test 
-Dtest=WorkflowDefinitionServiceTest` locally — all tests in the class pass.
   


-- 
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