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())) { if (Objects.isNull(basicResultVO.getData())) {
XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build(); XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build();
if (RespStatusEnum.SUCCESS.getCode().equals(cronTaskService.createGroup(xxlJobGroup).getStatus())) { 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(); return basicResultVO.getData();

@ -32,7 +32,7 @@ public class LinTongSendResult {
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class DataDTO { public static class DataDTO {
Integer code; Integer code;
String message; String message;
Long msgId; 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 { static {
CHANNEL_REGEX_EXP.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP); Map<Integer, String> tempMap = new HashMap<>();
CHANNEL_REGEX_EXP.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP); 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 { static {
RedisURI redisUri = RedisURI.Builder.redis(AustinFlinkConstant.REDIS_IP) 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()) .withPassword(AustinFlinkConstant.REDIS_PASSWORD.toCharArray())
.build(); .build();
redisClient = RedisClient.create(redisUri); redisClient = RedisClient.create(redisUri);

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

Loading…
Cancel
Save