You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by jo...@apache.org on 2020/01/06 03:23:41 UTC

[incubator-dolphinscheduler] branch dev updated: fix bug sonar: add null check in daghelper (#1719)

This is an automated email from the ASF dual-hosted git repository.

journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 13d5a5a  fix bug sonar: add null check in daghelper (#1719)
13d5a5a is described below

commit 13d5a5ae9bf26201fb753739513fd7ee6c34a337
Author: Yelli <51...@users.noreply.github.com>
AuthorDate: Mon Jan 6 11:23:34 2020 +0800

    fix bug sonar: add null check in daghelper (#1719)
    
    * modify FileUtils.readFile2Str
    
    * #1300 Add right alignment function in sql email content
    
    * cancel formatted for alert_mail_template.ftl
    
    * #747 sql task password Log desensitization
    
    * cancel mail_temple
    
    * edit ExcelUtils
    
    * modify test method name
    
    * #747 sql task password Log desensitization
    
    * #1544 workflow import
    
    * Constants add DATASOURCE_PASSWORD_REGEX
    
    * #747 sql task password Log desensitization
    
    * deal with import project have sub process
    
    * modify export process addTaskNodeParam method name
    
    * add testAddTaskNodeSpecialParam UT
    
    * add ProcessDefinitionServiceTest-ut to pom
    
    * add testImportSubProcess in ProcessDefinitionServiceTest
    
    * add testImportSubProcess in ProcessDefinitionServiceTest
    
    * add testImportProcessDefinition
    
    * fix sonar bug: not enough arguments
    
    * fix sonar bug: change condition & not enough arguments
    
    * fix bug sonar: add null check in daghelper && add hashcode method in ProcessData
    
    * fix bug sonar: add null check in daghelper
    
    * CollectionUtils.isEmpty()
---
 .../dolphinscheduler/dao/utils/DagHelper.java      | 31 +++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java
index 4096442..26d0f1e 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java
@@ -78,17 +78,17 @@ public class DagHelper {
         List<String> startNodeList = startNodeNameList;
 
         if(taskDependType != TaskDependType.TASK_POST
-                && startNodeList.size() == 0){
+                && CollectionUtils.isEmpty(startNodeList)){
             logger.error("start node list is empty! cannot continue run the process ");
             return destFlowNodeList;
         }
         List<TaskNode> destTaskNodeList = new ArrayList<>();
         List<TaskNode> tmpTaskNodeList = new ArrayList<>();
         if (taskDependType == TaskDependType.TASK_POST
-                && recoveryNodeNameList.size() > 0) {
+                && CollectionUtils.isNotEmpty(recoveryNodeNameList)) {
             startNodeList = recoveryNodeNameList;
         }
-        if (startNodeList == null || startNodeList.size() == 0) {
+        if (CollectionUtils.isEmpty(startNodeList)) {
             // no special designation start nodes
             tmpTaskNodeList = taskNodeList;
         } else {
@@ -126,10 +126,8 @@ public class DagHelper {
         List<TaskNode> resultList = new ArrayList<>();
         for (TaskNode taskNode : taskNodeList) {
             List<String> depList = taskNode.getDepList();
-            if (depList != null) {
-                if (depList.contains(startNode.getName())) {
-                    resultList.addAll(getFlowNodeListPost(taskNode, taskNodeList));
-                }
+            if (null != depList && null != startNode && depList.contains(startNode.getName())) {
+                resultList.addAll(getFlowNodeListPost(taskNode, taskNodeList));
             }
 
         }
@@ -149,9 +147,12 @@ public class DagHelper {
 
         List<TaskNode> resultList = new ArrayList<>();
 
-        List<String> depList = startNode.getDepList();
-        resultList.add(startNode);
-        if (depList == null || depList.size() == 0) {
+        List<String> depList = new ArrayList<>();
+        if (null != startNode) {
+            depList = startNode.getDepList();
+            resultList.add(startNode);
+        }
+        if (CollectionUtils.isEmpty(depList)) {
             return resultList;
         }
         for (String depNodeName : depList) {
@@ -180,7 +181,10 @@ public class DagHelper {
                                              TaskDependType depNodeType) throws Exception {
         ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class);
 
-        List<TaskNode> taskNodeList = processData.getTasks();
+        List<TaskNode> taskNodeList = new ArrayList<>();
+        if (null != processData) {
+            taskNodeList = processData.getTasks();
+        }
         List<TaskNode> destTaskNodeList = generateFlowNodeListByStartNode(taskNodeList, startNodeNameList, recoveryNodeNameList, depNodeType);
         if (destTaskNodeList.isEmpty()) {
             return null;
@@ -201,7 +205,10 @@ public class DagHelper {
         Map<String, TaskNode> forbidTaskNodeMap = new ConcurrentHashMap<>();
         ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class);
 
-        List<TaskNode> taskNodeList = processData.getTasks();
+        List<TaskNode> taskNodeList = new ArrayList<>();
+        if (null != processData) {
+            taskNodeList = processData.getTasks();
+        }
         for(TaskNode node : taskNodeList){
             if(node.isForbidden()){
                 forbidTaskNodeMap.putIfAbsent(node.getName(), node);