提交 26c96d8e 编写于 作者: K khadgarmage 提交者: Baoqi Wu

spotbugs: bug check and modify (#1018)

* spotbugs bug check and modify

* tmp var

* alter third parameter
上级 f250cdb0
......@@ -214,7 +214,7 @@ public class EnterpriseWeChatUtils {
}
StringBuilder contents = new StringBuilder(100);
contents.append(String.format("`%s`\n",title));
contents.append(String.format("`%s`%n",title));
for (String str : list){
contents.append(Constants.MARKDOWN_QUOTE);
contents.append(str);
......
......@@ -56,6 +56,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
......@@ -121,7 +124,7 @@ public class PropertyUtils {
return Boolean.parseBoolean(value);
}
return null;
return false;
}
/**
......
......@@ -870,7 +870,7 @@ public class ProcessDefinitionService extends BaseDAGService {
ProcessDefinition processDefinition = processDefineMapper.selectById(defineId);
if (processDefinition == null) {
logger.info("process define not exists");
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinition.getId());
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, defineId);
return result;
}
......
......@@ -120,9 +120,9 @@ public class ProcessInstanceService extends BaseDAGService {
}else{
WorkerGroup workerGroup = workerGroupMapper.selectById(processInstance.getWorkerGroupId());
if(workerGroup != null){
workerGroupName = DEFAULT;
}else{
workerGroupName = workerGroup.getName();
}else{
workerGroupName = DEFAULT;
}
}
processInstance.setWorkerGroupName(workerGroupName);
......@@ -165,14 +165,10 @@ public class ProcessInstanceService extends BaseDAGService {
}
int[] statusArray = null;
String statesStr = null;
// filter by state
if (stateType != null) {
statusArray = new int[]{stateType.ordinal()};
}
if (statusArray != null) {
statesStr = Arrays.toString(statusArray).replace("[", "").replace("]", "");
}
Date start = null;
Date end = null;
......
......@@ -53,8 +53,12 @@ public class TaskNodeRelation {
}
public boolean equals(TaskNodeRelation e){
return (e.getStartNode() == this.startNode && e.getEndNode() == this.endNode);
public boolean equals(Object o){
if (!(o instanceof TaskNodeRelation)) {
return false;
}
TaskNodeRelation relation = (TaskNodeRelation)o;
return (relation.getStartNode().equals(this.startNode) && relation.getEndNode().equals(this.endNode));
}
@Override
......
......@@ -153,8 +153,9 @@ public class FileUtils {
BufferedWriter bufferedWriter = null;
try {
File distFile = new File(filePath);
if (!distFile.getParentFile().exists()) {
distFile.getParentFile().mkdirs();
if (!distFile.getParentFile().exists() && !distFile.getParentFile().mkdirs()) {
FileUtils.logger.error("mkdir parent failed");
return false;
}
bufferedReader = new BufferedReader(new StringReader(content));
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
......
......@@ -156,7 +156,9 @@ public class OSUtils {
logger.error(e.getMessage(), e);
} finally {
try {
bufferedReader.close();
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
......
......@@ -60,6 +60,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
......@@ -173,7 +176,7 @@ public class PropertyUtils {
public static String[] getArray(String key, String splitStr) {
String value = getString(key);
if (value == null) {
return null;
return new String[0];
}
try {
String[] propertyArray = value.split(splitStr);
......@@ -181,7 +184,7 @@ public class PropertyUtils {
} catch (NumberFormatException e) {
logger.info(e.getMessage(),e);
}
return null;
return new String[0];
}
/**
......
......@@ -83,6 +83,7 @@ public class MonitorDBDao {
List<MonitorRecord> list = new ArrayList<>(1);
Connection conn = null;
Statement pstmt = null;
long maxConnections = 0;
long maxUsedConnections = 0;
long threadsConnections = 0;
......@@ -98,7 +99,7 @@ public class MonitorDBDao {
return list;
}
Statement pstmt = conn.createStatement();
pstmt = conn.createStatement();
ResultSet rs1 = pstmt.executeQuery("show global variables");
while(rs1.next()){
......@@ -124,6 +125,9 @@ public class MonitorDBDao {
state = 0;
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}
......
......@@ -147,6 +147,7 @@ public class TaskRecordDao {
int count = 0;
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConn();
if(conn == null){
......@@ -154,7 +155,6 @@ public class TaskRecordDao {
}
String sql = String.format("select count(1) as count from %s", table);
sql += getWhereString(filterMap);
PreparedStatement pstmt;
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
......@@ -165,6 +165,9 @@ public class TaskRecordDao {
logger.error("Exception ", e);
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}
......@@ -234,12 +237,12 @@ public class TaskRecordDao {
private static List<TaskRecord> getQueryResult(String selectSql) {
List<TaskRecord> recordList = new ArrayList<>();
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConn();
if(conn == null){
return recordList;
}
PreparedStatement pstmt;
pstmt = conn.prepareStatement(selectSql);
ResultSet rs = pstmt.executeQuery();
......@@ -251,6 +254,9 @@ public class TaskRecordDao {
logger.error("Exception ", e);
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}
......
......@@ -55,6 +55,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
......@@ -120,7 +123,7 @@ public class PropertyUtils {
return Boolean.parseBoolean(value);
}
return null;
return false;
}
/**
......
......@@ -74,7 +74,6 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
public Boolean waitTaskQuit(){
// query new state
taskInstance = processDao.findTaskInstanceById(taskInstance.getId());
Boolean result = true;
// task time out
Boolean checkTimeout = false;
TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter();
......@@ -89,7 +88,7 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
try {
if(this.processInstance == null){
logger.error("process instance not exists , master task exec thread exit");
return result;
return true;
}
// task instance add queue , waiting worker to kill
if(this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP){
......@@ -116,11 +115,13 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
} catch (Exception e) {
logger.error("exception: "+ e.getMessage(),e);
logger.error("wait task quit failed, instance id:{}, task id:{}",
processInstance.getId(), taskInstance.getId());
if (processInstance != null) {
logger.error("wait task quit failed, instance id:{}, task id:{}",
processInstance.getId(), taskInstance.getId());
}
}
}
return result;
return true;
}
......
......@@ -181,6 +181,7 @@ public abstract class AbstractTask {
break;
case FLINK:
paramsClass = FlinkParameters.class;
break;
case PYTHON:
paramsClass = PythonParameters.class;
break;
......
......@@ -303,7 +303,7 @@ public class SqlTask extends AbstractTask {
}
resultJSONArray.add(mapOfColValues);
}
resultSet.close();
logger.debug("execute sql : {}", JSONObject.toJSONString(resultJSONArray, SerializerFeature.WriteMapNullValue));
// if there is a result set
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册