fix: SpotBugs扫描分析(五):内部类改为static类型、parseXXX替换valueOf()(效率更高)、静态常量集合改为不可修改、减少拆箱装箱操作、优雅关闭流

pull/66/head
xiaoxiamo 6 months ago
parent b0e49b89be
commit 4be4e3c9f2

@ -84,7 +84,7 @@ public class XxlJobUtils {
if (Objects.isNull(basicResultVO.getData())) {
XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build();
if (RespStatusEnum.SUCCESS.getCode().equals(cronTaskService.createGroup(xxlJobGroup).getStatus())) {
return (int) cronTaskService.getGroupId(appName, jobHandlerName).getData();
return (Integer) cronTaskService.getGroupId(appName, jobHandlerName).getData();
}
}
return basicResultVO.getData();

@ -32,7 +32,7 @@ public class LinTongSendResult {
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataDTO {
public static class DataDTO {
Integer code;
String message;
Long msgId;

@ -31,11 +31,14 @@ public class SendAfterCheckAction implements BusinessProcess<SendTaskModel> {
/**
*
*/
protected static final Map<Integer, String> CHANNEL_REGEX_EXP = new HashMap<>();
protected static final Map<Integer, String> CHANNEL_REGEX_EXP;
static {
CHANNEL_REGEX_EXP.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
CHANNEL_REGEX_EXP.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
Map<Integer, String> tempMap = new HashMap<>();
tempMap.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
tempMap.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
// 初始化为不可变集合,避免被恶意修改
CHANNEL_REGEX_EXP = Collections.unmodifiableMap(tempMap);
}

@ -27,7 +27,7 @@ public class LettuceRedisUtils {
static {
RedisURI redisUri = RedisURI.Builder.redis(AustinFlinkConstant.REDIS_IP)
.withPort(Integer.valueOf(AustinFlinkConstant.REDIS_PORT))
.withPort(Integer.parseInt(AustinFlinkConstant.REDIS_PORT))
.withPassword(AustinFlinkConstant.REDIS_PASSWORD.toCharArray())
.build();
redisClient = RedisClient.create(redisUri);

@ -1,18 +1,19 @@
package com.java3y.austin.web.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
/**
* @author 3y
* multipartFile File
*/
@Slf4j
public class SpringFileUtils {
private SpringFileUtils() {
}
@ -26,23 +27,14 @@ public class SpringFileUtils {
public static File getFile(MultipartFile multipartFile) {
String fileName = multipartFile.getOriginalFilename();
File file = new File(fileName);
OutputStream out = null;
try {
out = new FileOutputStream(file);
try (OutputStream out = new FileOutputStream(file)){
byte[] ss = multipartFile.getBytes();
for (int i = 0; i < ss.length; i++) {
out.write(ss[i]);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (Objects.nonNull(out)) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
log.error("SpringFileUtils#getFile multipartFile is converted to File error:{}", e);
return null;
}
return file;
}

Loading…
Cancel
Save