Update LogServiceImpl.java

断言不适合用于参数验证,因为断言可以在JVM中的运行时被禁用,这意味着错误的操作设置将完全消除预期的检查。此外,失败的断言会抛出断言错误,而不是抛出某种类型的异常。抛出错误完全超出了正常程序中预期的捕获/抛出行为的正常范围。使用 if 代替 断言, 并抛出 IllegalArgumentException 更可控
pull/705/head
Night_mare 2021-12-02 20:04:15 +08:00 committed by GitHub
parent 8cb9b1dda9
commit 5e52bdcfa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -79,7 +79,9 @@ public class LogServiceImpl implements LogService {
@Override
@Transactional(rollbackFor = Exception.class)
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log) {
if (log == null) {
throw new IllegalArgumentException("Log 不能为 null!");
}
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
me.zhengjie.annotation.Log aopLog = method.getAnnotation(me.zhengjie.annotation.Log.class);
@ -88,12 +90,9 @@ public class LogServiceImpl implements LogService {
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
// 描述
if (log != null) {
log.setDescription(aopLog.value());
}
assert log != null;
log.setDescription(aopLog.value());
log.setRequestIp(ip);
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
log.setMethod(methodName);
log.setUsername(username);