github-advanced-security[bot] commented on code in PR #17058:
URL: 
https://github.com/apache/dolphinscheduler/pull/17058#discussion_r1995305777


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:
##########
@@ -57,6 +60,61 @@
         addTaskEdge(workflowTaskRelations);
     }
 
+    private void checkIfDAG(List<WorkflowTaskRelation> workflowTaskRelations, 
List<TaskDefinition> taskDefinitions) {
+        //If topology-sort-result`s size less than taskDefinitions`s size, 
then not a DAG
+        Map<Long, List<Long>> preTaskCodeMap = workflowTaskRelations
+                .stream()
+                
.collect(Collectors.groupingBy(WorkflowTaskRelation::getPostTaskCode,
+                        
Collectors.mapping(WorkflowTaskRelation::getPreTaskCode, Collectors.toList())));
+        Map<Long, List<Long>> postTaskCodeMap = workflowTaskRelations
+                .stream()
+                
.collect(Collectors.groupingBy(WorkflowTaskRelation::getPreTaskCode,
+                        
Collectors.mapping(WorkflowTaskRelation::getPostTaskCode, 
Collectors.toList())));
+
+        // build in-degree count
+        Map<Long, Integer> inDegreeCount = new HashMap<>();
+        for (TaskDefinition taskDefinition : taskDefinitions) {
+            List<Long> preTasks = preTaskCodeMap.get(taskDefinition.getCode());
+            if (preTasks == null) {
+                inDegreeCount.put(taskDefinition.getCode(), 0);
+            } else {
+                inDegreeCount.put(taskDefinition.getCode(), preTasks.size());
+            }
+        }
+
+        // Adds the task with zero-in-degree to the queue
+        Set<Long> visitTable = new HashSet<>();
+        Queue<Long> queue = new ArrayDeque<>();
+        for (Map.Entry<Long, Integer> entry : inDegreeCount.entrySet()) {
+            if (entry.getValue() == 0 && visitTable.add(entry.getKey())) {
+                queue.offer(entry.getKey());

Review Comment:
   ## Ignored error status of call
   
   Method checkIfDAG ignores exceptional return value of Queue<Long>.offer.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/5159)



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:
##########
@@ -57,6 +60,61 @@
         addTaskEdge(workflowTaskRelations);
     }
 
+    private void checkIfDAG(List<WorkflowTaskRelation> workflowTaskRelations, 
List<TaskDefinition> taskDefinitions) {
+        //If topology-sort-result`s size less than taskDefinitions`s size, 
then not a DAG
+        Map<Long, List<Long>> preTaskCodeMap = workflowTaskRelations
+                .stream()
+                
.collect(Collectors.groupingBy(WorkflowTaskRelation::getPostTaskCode,
+                        
Collectors.mapping(WorkflowTaskRelation::getPreTaskCode, Collectors.toList())));
+        Map<Long, List<Long>> postTaskCodeMap = workflowTaskRelations
+                .stream()
+                
.collect(Collectors.groupingBy(WorkflowTaskRelation::getPreTaskCode,
+                        
Collectors.mapping(WorkflowTaskRelation::getPostTaskCode, 
Collectors.toList())));
+
+        // build in-degree count
+        Map<Long, Integer> inDegreeCount = new HashMap<>();
+        for (TaskDefinition taskDefinition : taskDefinitions) {
+            List<Long> preTasks = preTaskCodeMap.get(taskDefinition.getCode());
+            if (preTasks == null) {
+                inDegreeCount.put(taskDefinition.getCode(), 0);
+            } else {
+                inDegreeCount.put(taskDefinition.getCode(), preTasks.size());
+            }
+        }
+
+        // Adds the task with zero-in-degree to the queue
+        Set<Long> visitTable = new HashSet<>();
+        Queue<Long> queue = new ArrayDeque<>();
+        for (Map.Entry<Long, Integer> entry : inDegreeCount.entrySet()) {
+            if (entry.getValue() == 0 && visitTable.add(entry.getKey())) {
+                queue.offer(entry.getKey());
+            }
+        }
+
+        // topology sort
+        Set<Long> resultTable = new HashSet<>();
+        while (!queue.isEmpty()) {
+            Long taskCode = queue.poll();
+            resultTable.add(taskCode);
+
+            List<Long> postCodes = postTaskCodeMap.get(taskCode);
+            if (postCodes == null) {
+                continue;
+            }
+            for (Long postCode : postCodes) {
+                inDegreeCount.put(postCode, inDegreeCount.get(postCode) - 1);
+
+                if (inDegreeCount.get(postCode) == 0) {
+                    queue.offer(postCode);

Review Comment:
   ## Ignored error status of call
   
   Method checkIfDAG ignores exceptional return value of Queue<Long>.offer.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/5160)



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