Browse Source

[improvement-#12416] Use CollectionUtils.isEmpty judge the collection isEmpty to avoid NPE (#12449)

3.2.0-release
fuchanghai 2 years ago committed by GitHub
parent
commit
f0a34cddec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java
  2. 4
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsAlertChannel.java
  3. 2
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/JSONUtils.java
  4. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java
  5. 11
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java
  6. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  7. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  8. 25
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  9. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
  10. 3
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
  11. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  12. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
  13. 6
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringGlobalParams.java
  14. 9
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  15. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java
  16. 4
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchParameters.java
  17. 4
      dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/message/MessageRetryRunner.java

3
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java

@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.commons.codec.binary.StringUtils; import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@ -108,7 +109,7 @@ public final class FeiShuSender {
if (alertData.getContent() != null) { if (alertData.getContent() != null) {
List<Map> list = JSONUtils.toList(alertData.getContent(), Map.class); List<Map> list = JSONUtils.toList(alertData.getContent(), Map.class);
if (list.isEmpty()) { if (CollectionUtils.isEmpty(list)) {
return alertData.getTitle() + alertData.getContent(); return alertData.getTitle() + alertData.getContent();
} }

4
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsAlertChannel.java

@ -22,6 +22,8 @@ import org.apache.dolphinscheduler.alert.api.AlertData;
import org.apache.dolphinscheduler.alert.api.AlertInfo; import org.apache.dolphinscheduler.alert.api.AlertInfo;
import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.commons.collections.MapUtils;
import java.util.Map; import java.util.Map;
public final class WebexTeamsAlertChannel implements AlertChannel { public final class WebexTeamsAlertChannel implements AlertChannel {
@ -30,7 +32,7 @@ public final class WebexTeamsAlertChannel implements AlertChannel {
public AlertResult process(AlertInfo alertInfo) { public AlertResult process(AlertInfo alertInfo) {
AlertData alertData = alertInfo.getAlertData(); AlertData alertData = alertInfo.getAlertData();
Map<String, String> alertParams = alertInfo.getAlertParams(); Map<String, String> alertParams = alertInfo.getAlertParams();
if (alertParams == null || alertParams.size() == 0) { if (MapUtils.isEmpty(alertParams)) {
return new AlertResult("false", "WebexTeams alert params is empty"); return new AlertResult("false", "WebexTeams alert params is empty");
} }

2
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/JSONUtils.java

@ -331,7 +331,7 @@ public class JSONUtils {
public static ObjectNode parseObject(String text) { public static ObjectNode parseObject(String text) {
try { try {
if (text.isEmpty()) { if (StringUtils.isEmpty(text)) {
return parseObject(text, ObjectNode.class); return parseObject(text, ObjectNode.class);
} else { } else {
return (ObjectNode) objectMapper.readTree(text); return (ObjectNode) objectMapper.readTree(text);

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java

@ -21,6 +21,8 @@ import org.apache.dolphinscheduler.api.dto.FavTaskDto;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.config.YamlPropertySourceFactory; import org.apache.dolphinscheduler.common.config.YamlPropertySourceFactory;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -55,7 +57,7 @@ public class TaskTypeConfiguration {
private static final List<FavTaskDto> defaultTaskTypes = new ArrayList<>(); private static final List<FavTaskDto> defaultTaskTypes = new ArrayList<>();
public List<FavTaskDto> getDefaultTaskTypes() { public List<FavTaskDto> getDefaultTaskTypes() {
if (!defaultTaskTypes.isEmpty()) { if (CollectionUtils.isNotEmpty(defaultTaskTypes)) {
return defaultTaskTypes; return defaultTaskTypes;
} }
printDefaultTypes(); printDefaultTypes();

11
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java

@ -114,7 +114,7 @@ public class ResourcePermissionCheckServiceImpl
originResSet.removeAll(ownResSets); originResSet.removeAll(ownResSets);
if (CollectionUtils.isNotEmpty(originResSet)) if (CollectionUtils.isNotEmpty(originResSet))
logger.warn("User does not have resource permission on associated resources, userId:{}", userId); logger.warn("User does not have resource permission on associated resources, userId:{}", userId);
return originResSet.isEmpty(); return CollectionUtils.isEmpty(originResSet);
} }
return true; return true;
} }
@ -180,7 +180,8 @@ public class ResourcePermissionCheckServiceImpl
return Collections.emptySet(); return Collections.emptySet();
} }
List<Queue> queues = queueMapper.selectList(null); List<Queue> queues = queueMapper.selectList(null);
return queues.isEmpty() ? Collections.emptySet() : queues.stream().map(Queue::getId).collect(toSet()); return CollectionUtils.isEmpty(queues) ? Collections.emptySet()
: queues.stream().map(Queue::getId).collect(toSet());
} }
} }
@ -266,7 +267,7 @@ public class ResourcePermissionCheckServiceImpl
@Override @Override
public Set<Integer> listAuthorizedResource(int userId, Logger logger) { public Set<Integer> listAuthorizedResource(int userId, Logger logger) {
List<UdfFunc> udfFuncList = udfFuncMapper.listAuthorizedUdfByUserId(userId); List<UdfFunc> udfFuncList = udfFuncMapper.listAuthorizedUdfByUserId(userId);
if (udfFuncList.isEmpty()) { if (CollectionUtils.isEmpty(udfFuncList)) {
return Collections.emptySet(); return Collections.emptySet();
} }
return udfFuncList.stream().map(UdfFunc::getId).collect(toSet()); return udfFuncList.stream().map(UdfFunc::getId).collect(toSet());
@ -295,7 +296,7 @@ public class ResourcePermissionCheckServiceImpl
@Override @Override
public Set<Integer> listAuthorizedResource(int userId, Logger logger) { public Set<Integer> listAuthorizedResource(int userId, Logger logger) {
List<TaskGroup> taskGroupList = taskGroupMapper.listAuthorizedResource(userId); List<TaskGroup> taskGroupList = taskGroupMapper.listAuthorizedResource(userId);
if (taskGroupList.isEmpty()) { if (CollectionUtils.isEmpty(taskGroupList)) {
return Collections.emptySet(); return Collections.emptySet();
} }
return taskGroupList.stream().map(TaskGroup::getId).collect(Collectors.toSet()); return taskGroupList.stream().map(TaskGroup::getId).collect(Collectors.toSet());
@ -354,7 +355,7 @@ public class ResourcePermissionCheckServiceImpl
@Override @Override
public Set<Integer> listAuthorizedResource(int userId, Logger logger) { public Set<Integer> listAuthorizedResource(int userId, Logger logger) {
List<Environment> environments = environmentMapper.queryAllEnvironmentList(); List<Environment> environments = environmentMapper.queryAllEnvironmentList();
if (environments.isEmpty()) { if (CollectionUtils.isEmpty(environments)) {
return Collections.emptySet(); return Collections.emptySet();
} }
return environments.stream().map(Environment::getId).collect(Collectors.toSet()); return environments.stream().map(Environment::getId).collect(Collectors.toSet());

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -968,7 +968,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Set<Long> diffCode = Set<Long> diffCode =
definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet()); definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet());
if (!diffCode.isEmpty()) { if (CollectionUtils.isNotEmpty(diffCode)) {
logger.error("Process definition does not exist, processCodes:{}.", logger.error("Process definition does not exist, processCodes:{}.",
diffCode.stream().map(String::valueOf).collect(Collectors.joining(Constants.COMMA))); diffCode.stream().map(String::valueOf).collect(Collectors.joining(Constants.COMMA)));
throw new ServiceException(Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR, throw new ServiceException(Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR,

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java

@ -889,7 +889,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
ganttDto.setTaskNames(nodeList); ganttDto.setTaskNames(nodeList);
List<Task> taskList = new ArrayList<>(); List<Task> taskList = new ArrayList<>();
if (!nodeList.isEmpty()) { if (CollectionUtils.isNotEmpty(nodeList)) {
List<Long> taskCodes = nodeList.stream().map(Long::parseLong).collect(Collectors.toList()); List<Long> taskCodes = nodeList.stream().map(Long::parseLong).collect(Collectors.toList());
List<TaskInstance> taskInstances = taskInstanceMapper.queryByProcessInstanceIdsAndTaskCodes( List<TaskInstance> taskInstances = taskInstanceMapper.queryByProcessInstanceIdsAndTaskCodes(
Collections.singletonList(processInstanceId), taskCodes); Collections.singletonList(processInstanceId), taskCodes);

25
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java

@ -66,6 +66,7 @@ import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.dolphinscheduler.service.task.TaskPluginManager; import org.apache.dolphinscheduler.service.task.TaskPluginManager;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -150,7 +151,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class);
if (taskDefinitionLogs.isEmpty()) { if (CollectionUtils.isEmpty(taskDefinitionLogs)) {
logger.warn("Parameter taskDefinitionJson is invalid."); logger.warn("Parameter taskDefinitionJson is invalid.");
putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson);
return result; return result;
@ -336,7 +337,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
// upstreamTaskCodes - queryUpStreamTaskCodes // upstreamTaskCodes - queryUpStreamTaskCodes
Set<Long> diffCode = upstreamTaskCodes.stream().filter(code -> !queryUpStreamTaskCodes.contains(code)) Set<Long> diffCode = upstreamTaskCodes.stream().filter(code -> !queryUpStreamTaskCodes.contains(code))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (!diffCode.isEmpty()) { if (CollectionUtils.isNotEmpty(diffCode)) {
String taskCodes = StringUtils.join(diffCode, Constants.COMMA); String taskCodes = StringUtils.join(diffCode, Constants.COMMA);
logger.error("Some task definitions with parameter upstreamCodes do not exist, taskDefinitionCodes:{}.", logger.error("Some task definitions with parameter upstreamCodes do not exist, taskDefinitionCodes:{}.",
taskCodes); taskCodes);
@ -438,7 +439,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
// Whether task have downstream tasks // Whether task have downstream tasks
List<ProcessTaskRelation> processTaskRelationList = List<ProcessTaskRelation> processTaskRelationList =
processTaskRelationMapper.queryDownstreamByTaskCode(taskDefinition.getCode()); processTaskRelationMapper.queryDownstreamByTaskCode(taskDefinition.getCode());
if (!processTaskRelationList.isEmpty()) { if (CollectionUtils.isNotEmpty(processTaskRelationList)) {
Set<Long> postTaskCodes = processTaskRelationList Set<Long> postTaskCodes = processTaskRelationList
.stream() .stream()
.map(ProcessTaskRelation::getPostTaskCode) .map(ProcessTaskRelation::getPostTaskCode)
@ -474,7 +475,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
// Delete task upstream tasks if exists // Delete task upstream tasks if exists
List<ProcessTaskRelation> taskRelationList = List<ProcessTaskRelation> taskRelationList =
processTaskRelationMapper.queryUpstreamByCode(taskDefinition.getProjectCode(), taskCode); processTaskRelationMapper.queryUpstreamByCode(taskDefinition.getProjectCode(), taskCode);
if (!taskRelationList.isEmpty()) { if (CollectionUtils.isNotEmpty(taskRelationList)) {
logger.debug( logger.debug(
"Task definition has upstream tasks, start handle them after delete task, taskDefinitionCode:{}.", "Task definition has upstream tasks, start handle them after delete task, taskDefinitionCode:{}.",
taskCode); taskCode);
@ -540,7 +541,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
List<ProcessTaskRelation> taskRelationList = List<ProcessTaskRelation> taskRelationList =
processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode);
if (!taskRelationList.isEmpty()) { if (CollectionUtils.isNotEmpty(taskRelationList)) {
logger.info( logger.info(
"Task definition has upstream tasks, start handle them after update task, taskDefinitionCode:{}.", "Task definition has upstream tasks, start handle them after update task, taskDefinitionCode:{}.",
taskCode); taskCode);
@ -614,7 +615,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
List<ProcessTaskRelation> taskRelationList = List<ProcessTaskRelation> taskRelationList =
processTaskRelationMapper.queryUpstreamByCode(taskDefinitionUpdate.getProjectCode(), taskCode); processTaskRelationMapper.queryUpstreamByCode(taskDefinitionUpdate.getProjectCode(), taskCode);
if (!taskRelationList.isEmpty()) { if (CollectionUtils.isNotEmpty(taskRelationList)) {
logger.info( logger.info(
"Task definition has upstream tasks, start handle them after update task, taskDefinitionCode:{}.", "Task definition has upstream tasks, start handle them after update task, taskDefinitionCode:{}.",
taskCode); taskCode);
@ -794,13 +795,13 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
} }
Map<Long, TaskDefinition> queryUpStreamTaskCodeMap; Map<Long, TaskDefinition> queryUpStreamTaskCodeMap;
if (!upstreamTaskCodes.isEmpty()) { if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
List<TaskDefinition> upstreamTaskDefinitionList = taskDefinitionMapper.queryByCodeList(upstreamTaskCodes); List<TaskDefinition> upstreamTaskDefinitionList = taskDefinitionMapper.queryByCodeList(upstreamTaskCodes);
queryUpStreamTaskCodeMap = upstreamTaskDefinitionList.stream() queryUpStreamTaskCodeMap = upstreamTaskDefinitionList.stream()
.collect(Collectors.toMap(TaskDefinition::getCode, taskDefinition -> taskDefinition)); .collect(Collectors.toMap(TaskDefinition::getCode, taskDefinition -> taskDefinition));
// upstreamTaskCodes - queryUpStreamTaskCodeMap.keySet // upstreamTaskCodes - queryUpStreamTaskCodeMap.keySet
upstreamTaskCodes.removeAll(queryUpStreamTaskCodeMap.keySet()); upstreamTaskCodes.removeAll(queryUpStreamTaskCodeMap.keySet());
if (!upstreamTaskCodes.isEmpty()) { if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
String notExistTaskCodes = StringUtils.join(upstreamTaskCodes, Constants.COMMA); String notExistTaskCodes = StringUtils.join(upstreamTaskCodes, Constants.COMMA);
logger.error("Some task definitions in parameter upstreamTaskCodes do not exist, notExistTaskCodes:{}.", logger.error("Some task definitions in parameter upstreamTaskCodes do not exist, notExistTaskCodes:{}.",
notExistTaskCodes); notExistTaskCodes);
@ -810,7 +811,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} else { } else {
queryUpStreamTaskCodeMap = new HashMap<>(); queryUpStreamTaskCodeMap = new HashMap<>();
} }
if (!upstreamTaskRelations.isEmpty()) { if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
ProcessTaskRelation taskRelation = upstreamTaskRelations.get(0); ProcessTaskRelation taskRelation = upstreamTaskRelations.get(0);
List<ProcessTaskRelation> processTaskRelations = List<ProcessTaskRelation> processTaskRelations =
processTaskRelationMapper.queryByProcessCode(projectCode, taskRelation.getProcessDefinitionCode()); processTaskRelationMapper.queryByProcessCode(projectCode, taskRelation.getProcessDefinitionCode());
@ -834,7 +835,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
taskRelation.setPreTaskVersion(queryUpStreamTask.getValue().getVersion()); taskRelation.setPreTaskVersion(queryUpStreamTask.getValue().getVersion());
processTaskRelationList.add(taskRelation); processTaskRelationList.add(taskRelation);
} }
if (queryUpStreamTaskCodeMap.isEmpty() && !processTaskRelationList.isEmpty()) { if (MapUtils.isEmpty(queryUpStreamTaskCodeMap) && CollectionUtils.isNotEmpty(processTaskRelationList)) {
processTaskRelationList.add(processTaskRelationList.get(0)); processTaskRelationList.add(processTaskRelationList.get(0));
} }
updateDag(loginUser, taskRelation.getProcessDefinitionCode(), processTaskRelations, updateDag(loginUser, taskRelation.getProcessDefinitionCode(), processTaskRelations,
@ -888,7 +889,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
if (switchVersion > 0) { if (switchVersion > 0) {
List<ProcessTaskRelation> taskRelationList = List<ProcessTaskRelation> taskRelationList =
processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode);
if (!taskRelationList.isEmpty()) { if (CollectionUtils.isNotEmpty(taskRelationList)) {
logger.info( logger.info(
"Task definition has upstream tasks, start handle them after switch task, taskDefinitionCode:{}.", "Task definition has upstream tasks, start handle them after switch task, taskDefinitionCode:{}.",
taskCode); taskCode);
@ -1022,7 +1023,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
taskDefinitionMapper.queryDefineListPaging(page, projectCode, searchWorkflowName, taskDefinitionMapper.queryDefineListPaging(page, projectCode, searchWorkflowName,
searchTaskName, taskType, taskExecuteType); searchTaskName, taskType, taskExecuteType);
List<TaskMainInfo> records = taskMainInfoIPage.getRecords(); List<TaskMainInfo> records = taskMainInfoIPage.getRecords();
if (!records.isEmpty()) { if (CollectionUtils.isNotEmpty(records)) {
Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>(); Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>();
for (TaskMainInfo info : records) { for (TaskMainInfo info : records) {
taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> { taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> {

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java

@ -25,6 +25,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -339,7 +341,7 @@ public class JSONUtils {
public static ObjectNode parseObject(String text) { public static ObjectNode parseObject(String text) {
try { try {
if (text.isEmpty()) { if (StringUtils.isEmpty(text)) {
return parseObject(text, ObjectNode.class); return parseObject(text, ObjectNode.class);
} else { } else {
return (ObjectNode) objectMapper.readTree(text); return (ObjectNode) objectMapper.readTree(text);

3
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java

@ -21,6 +21,7 @@ import static java.util.Collections.emptyList;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.commons.collections.CollectionUtils;
import org.apache.http.conn.util.InetAddressUtils; import org.apache.http.conn.util.InetAddressUtils;
import java.io.IOException; import java.io.IOException;
@ -266,7 +267,7 @@ public class NetUtils {
} }
private static NetworkInterface findAddress(List<NetworkInterface> validNetworkInterfaces) { private static NetworkInterface findAddress(List<NetworkInterface> validNetworkInterfaces) {
if (validNetworkInterfaces.isEmpty()) { if (CollectionUtils.isEmpty(validNetworkInterfaces)) {
return null; return null;
} }
String networkPriority = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY, String networkPriority = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY,

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java

@ -241,7 +241,7 @@ public class OSUtils {
int startPos = 0; int startPos = 0;
int endPos = lines.length - 2; int endPos = lines.length - 2;
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
if (lines[i].isEmpty()) { if (StringUtils.isEmpty(lines[i])) {
continue; continue;
} }

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java

@ -22,6 +22,8 @@ import static org.apache.dolphinscheduler.common.Constants.COMMON_PROPERTIES_PAT
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.ResUploadType; import org.apache.dolphinscheduler.common.enums.ResUploadType;
import org.apache.commons.collections.CollectionUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
@ -280,7 +282,7 @@ public class PropertyUtils {
return null; return null;
} }
Set<Object> keys = properties.keySet(); Set<Object> keys = properties.keySet();
if (keys.isEmpty()) { if (CollectionUtils.isEmpty(keys)) {
return null; return null;
} }
Map<String, String> propertiesMap = new HashMap<>(); Map<String, String> propertiesMap = new HashMap<>();

6
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringGlobalParams.java

@ -147,7 +147,7 @@ public class CuringGlobalParams implements CuringParamsService {
parameters.setVarPool(taskInstance.getVarPool()); parameters.setVarPool(taskInstance.getVarPool());
Map<String, Property> varParams = parameters.getVarPoolMap(); Map<String, Property> varParams = parameters.getVarPoolMap();
if (globalParams.isEmpty() && localParams.isEmpty() && varParams.isEmpty()) { if (MapUtils.isEmpty(globalParams) && MapUtils.isEmpty(localParams) && MapUtils.isEmpty(varParams)) {
return null; return null;
} }
// if it is a complement, // if it is a complement,
@ -166,10 +166,10 @@ public class CuringGlobalParams implements CuringParamsService {
} }
params.put(PARAMETER_TASK_INSTANCE_ID, Integer.toString(taskInstance.getId())); params.put(PARAMETER_TASK_INSTANCE_ID, Integer.toString(taskInstance.getId()));
if (varParams.size() != 0) { if (MapUtils.isNotEmpty(varParams)) {
globalParams.putAll(varParams); globalParams.putAll(varParams);
} }
if (localParams.size() != 0) { if (MapUtils.isNotEmpty(localParams)) {
globalParams.putAll(localParams); globalParams.putAll(localParams);
} }

9
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

@ -137,6 +137,7 @@ import org.apache.dolphinscheduler.service.utils.DagHelper;
import org.apache.dolphinscheduler.spi.enums.ResourceType; import org.apache.dolphinscheduler.spi.enums.ResourceType;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -746,7 +747,7 @@ public class ProcessServiceImpl implements ProcessService {
queryReleaseSchedulerListByProcessDefinitionCode(command.getProcessDefinitionCode()); queryReleaseSchedulerListByProcessDefinitionCode(command.getProcessDefinitionCode());
List<Date> complementDateList = CronUtils.getSelfFireDateList(start, end, schedules); List<Date> complementDateList = CronUtils.getSelfFireDateList(start, end, schedules);
if (complementDateList.size() > 0) { if (CollectionUtils.isNotEmpty(complementDateList)) {
scheduleTime = complementDateList.get(0); scheduleTime = complementDateList.get(0);
} else { } else {
logger.error("set scheduler time error: complement date list is empty, command: {}", logger.error("set scheduler time error: complement date list is empty, command: {}",
@ -841,7 +842,7 @@ public class ProcessServiceImpl implements ProcessService {
// set start param into global params // set start param into global params
Map<String, String> globalMap = processDefinition.getGlobalParamMap(); Map<String, String> globalMap = processDefinition.getGlobalParamMap();
List<Property> globalParamList = processDefinition.getGlobalParamList(); List<Property> globalParamList = processDefinition.getGlobalParamList();
if (startParamMap.size() > 0 && globalMap != null) { if (MapUtils.isNotEmpty(startParamMap) && globalMap != null) {
// start param to overwrite global param // start param to overwrite global param
for (Map.Entry<String, String> param : globalMap.entrySet()) { for (Map.Entry<String, String> param : globalMap.entrySet()) {
String val = startParamMap.get(param.getKey()); String val = startParamMap.get(param.getKey());
@ -1159,7 +1160,7 @@ public class ProcessServiceImpl implements ProcessService {
complementDate = CronUtils.getSelfScheduleDateList(cmdParam); complementDate = CronUtils.getSelfScheduleDateList(cmdParam);
} }
if (complementDate.size() > 0 && Flag.NO == processInstance.getIsSubProcess()) { if (CollectionUtils.isNotEmpty(complementDate) && Flag.NO == processInstance.getIsSubProcess()) {
processInstance.setScheduleTime(complementDate.get(0)); processInstance.setScheduleTime(complementDate.get(0));
} }
@ -1473,7 +1474,7 @@ public class ProcessServiceImpl implements ProcessService {
} }
processMapStr = JSONUtils.toJsonString(cmdParam); processMapStr = JSONUtils.toJsonString(cmdParam);
} }
if (fatherParams.size() != 0) { if (MapUtils.isNotEmpty(fatherParams)) {
cmdParam.put(CMD_PARAM_FATHER_PARAMS, JSONUtils.toJsonString(fatherParams)); cmdParam.put(CMD_PARAM_FATHER_PARAMS, JSONUtils.toJsonString(fatherParams));
processMapStr = JSONUtils.toJsonString(cmdParam); processMapStr = JSONUtils.toJsonString(cmdParam);
} }

2
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java

@ -266,7 +266,7 @@ public class TimePlaceholderUtils {
if (Character.isDigit(expression.charAt(i))) { if (Character.isDigit(expression.charAt(i))) {
num = num + expression.charAt(i); num = num + expression.charAt(i);
} else { } else {
if (!num.isEmpty()) { if (!StringUtils.isEmpty(num)) {
result.add(num); result.add(num);
} }
result.add(expression.charAt(i) + ""); result.add(expression.charAt(i) + "");

4
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchParameters.java

@ -22,6 +22,8 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.spi.utils.StringUtils; import org.apache.dolphinscheduler.spi.utils.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import java.util.List; import java.util.List;
public class SwitchParameters extends AbstractParameters { public class SwitchParameters extends AbstractParameters {
@ -86,7 +88,7 @@ public class SwitchParameters extends AbstractParameters {
} }
// validate conditions must have next node // validate conditions must have next node
List<SwitchCondition> conditions = this.switchResult.getDependTaskList(); List<SwitchCondition> conditions = this.switchResult.getDependTaskList();
if (conditions != null && conditions.size() != 0) { if (CollectionUtils.isNotEmpty(conditions)) {
if (conditions.stream() if (conditions.stream()
.anyMatch(e -> (StringUtils.isNotEmpty(e.getCondition()) && e.getNextNode() == null))) { .anyMatch(e -> (StringUtils.isNotEmpty(e.getCondition()) && e.getNextNode() == null))) {
return false; return false;

4
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/message/MessageRetryRunner.java

@ -24,6 +24,8 @@ import org.apache.dolphinscheduler.remote.command.BaseCommand;
import org.apache.dolphinscheduler.remote.command.CommandType; import org.apache.dolphinscheduler.remote.command.CommandType;
import org.apache.dolphinscheduler.service.utils.LoggerUtils; import org.apache.dolphinscheduler.service.utils.LoggerUtils;
import org.apache.commons.collections.MapUtils;
import java.time.Duration; import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -101,7 +103,7 @@ public class MessageRetryRunner extends BaseDaemonThread {
public void run() { public void run() {
while (!ServerLifeCycleManager.isStopped()) { while (!ServerLifeCycleManager.isStopped()) {
try { try {
if (needToRetryMessages.isEmpty()) { if (MapUtils.isEmpty(needToRetryMessages)) {
Thread.sleep(MESSAGE_RETRY_WINDOW); Thread.sleep(MESSAGE_RETRY_WINDOW);
} }

Loading…
Cancel
Save