Sonar

158 阅读1分钟

Fields in a "Serializable" class should either be transient or serializable

public class RespUtil<T extends Serializable> implements Serializable {
    private static final long serialVersionUID = -1L;

    private int code;

    private String message;

    private T data;

    private RespUtil() {
    }

    private RespUtil(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T extends Serializable> RespUtil<T> fail(T data) {
        return new RespUtil<>(HttpCode.SERVER_ERROR.getHttpCode(), HttpCode.SERVER_ERROR.getMessage(), data);
    }

    public static <T extends Serializable> RespUtil<T> success(T data) {
        return new RespUtil<>(HttpCode.SUCCESS_200.getHttpCode(), HttpCode.SUCCESS_200.getMessage(), data);
    }
}

"Preconditions" and logging arguments should not require evaluation

“先决条件”和日志参数不应该需要计算,换言之,在调用"Preconditions" 和 logging 方法时,参数应该是可确定的

ChannelId channelId = ctx.channel().id();
String asLongText = channelId.asLongText();
String asShortText = channelId.asShortText();
log.info("[xuegao-im-chat-2022][WsServerHandler][handlerRemoved][长id={}][短id={}]", asLongText, asShortText);

引用

Sonar Java默认扫描规则 (devnote.pro)