github-code-scanning[bot] commented on code in PR #13023:
URL: 
https://github.com/apache/dolphinscheduler/pull/13023#discussion_r1033261424


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -812,78 +811,72 @@
         if (result.get(Constants.STATUS) != Status.SUCCESS && 
taskDefinitionToUpdate == null) {
             return result;
         }
+        // get sourceUpstreamTaskCodeSet
         List<ProcessTaskRelation> upstreamTaskRelations =
                 processTaskRelationMapper.queryUpstreamByCode(projectCode, 
taskCode);
-        Set<Long> upstreamCodeSet =
+        Set<Long> sourceUpstreamCodeSet =
                 
upstreamTaskRelations.stream().map(ProcessTaskRelation::getPreTaskCode).collect(Collectors.toSet());
-        Set<Long> upstreamTaskCodes = Collections.emptySet();
+        // get updateUpstreamTaskCodeSet
+        Set<Long> updateUpstreamTaskCodeSet = Collections.emptySet();
         if (StringUtils.isNotEmpty(upstreamCodes)) {
-            upstreamTaskCodes = 
Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)
+            updateUpstreamTaskCodeSet = 
Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)
                     .collect(Collectors.toSet());
         }
-        if (CollectionUtils.isEqualCollection(upstreamCodeSet, 
upstreamTaskCodes) && taskDefinitionToUpdate == null) {
+        if (CollectionUtils.isEqualCollection(sourceUpstreamCodeSet, 
updateUpstreamTaskCodeSet)
+                && taskDefinitionToUpdate == null) {
             putMsg(result, Status.SUCCESS);
             return result;
-        } else {
-            if (taskDefinitionToUpdate == null) {
-                taskDefinitionToUpdate = 
JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
-            }
+        } else if (taskDefinitionToUpdate == null) {
+            taskDefinitionToUpdate = 
JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
         }
-        Map<Long, TaskDefinition> queryUpStreamTaskCodeMap;
-        if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-            List<TaskDefinition> upstreamTaskDefinitionList = 
taskDefinitionMapper.queryByCodeList(upstreamTaskCodes);
-            queryUpStreamTaskCodeMap = upstreamTaskDefinitionList.stream()
-                    .collect(Collectors.toMap(TaskDefinition::getCode, 
taskDefinition -> taskDefinition));
-            // upstreamTaskCodes - queryUpStreamTaskCodeMap.keySet
-            upstreamTaskCodes.removeAll(queryUpStreamTaskCodeMap.keySet());
-            if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-                String notExistTaskCodes = StringUtils.join(upstreamTaskCodes, 
Constants.COMMA);
-                logger.error("Some task definitions in parameter 
upstreamTaskCodes do not exist, notExistTaskCodes:{}.",
-                        notExistTaskCodes);
-                putMsg(result, Status.TASK_DEFINE_NOT_EXIST, 
notExistTaskCodes);
-                return result;
-            }
-        } else {
-            queryUpStreamTaskCodeMap = new HashMap<>();
+        // get survive updateUpstreamTask
+        Map<Long, TaskDefinition> updateUpstreamTask = 
getUpdateUpstreamTaskCodeMap(updateUpstreamTaskCodeSet, result);

Review Comment:
   ## Unread local variable
   
   Variable 'Map<Long,TaskDefinition> updateUpstreamTask' is never read.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2355)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -812,78 +811,72 @@
         if (result.get(Constants.STATUS) != Status.SUCCESS && 
taskDefinitionToUpdate == null) {
             return result;
         }
+        // get sourceUpstreamTaskCodeSet
         List<ProcessTaskRelation> upstreamTaskRelations =
                 processTaskRelationMapper.queryUpstreamByCode(projectCode, 
taskCode);
-        Set<Long> upstreamCodeSet =
+        Set<Long> sourceUpstreamCodeSet =
                 
upstreamTaskRelations.stream().map(ProcessTaskRelation::getPreTaskCode).collect(Collectors.toSet());
-        Set<Long> upstreamTaskCodes = Collections.emptySet();
+        // get updateUpstreamTaskCodeSet
+        Set<Long> updateUpstreamTaskCodeSet = Collections.emptySet();
         if (StringUtils.isNotEmpty(upstreamCodes)) {
-            upstreamTaskCodes = 
Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)
+            updateUpstreamTaskCodeSet = 
Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2356)



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