spotbugs~lombok生成的Date屬性引發的EI_EXPOSE_REP問題

EI_EXPOSE_REP是spotbugs,findbugs裏經過代碼分析拋出來的代碼安全性問題,主要表示在一個Date類型的字段在進行@Getter註解時,沒有檢查它是否爲空,這塊咱們有兩種解決方案,第一種是手寫Date類型的字段的Getter方法;第二種是安裝com.google.code.findbugs:findbugs包,而後使用它的@SuppressFBWarnings註釋,把這種問題忽略,咱們介紹一下這兩種方法。安全

第一種

重寫它的setter方法this

public void setBillDate(Date billDate) {
    this.billDate = billDate != null ? new Date(billDate.getTime()) : null;
}

第二種

使用引用findbug包google

<dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>findbugs</artifactId>
            <version>3.0.1</version>
        </dependency>

在實體上添加SuppressFBWarnings註解便可code

@Data
@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"}, justification = "I prefer to suppress these FindBugs warnings")
public abstract class BaseEntity<T extends Model<?>> extends Model<T> {
    private Date createTime;
    private String createUser;
    private Date updateTime;
    private String updateUser;

}

再進行spotbugs:spotbugs時,這個錯誤就沒有了。get

相關文章
相關標籤/搜索