zoukankan      html  css  js  c++  java
  • spotbugs~lombok生成的Date属性引起的EI_EXPOSE_REP问题

    EI_EXPOSE_REP是spotbugs,findbugs里通过代码分析抛出来的代码安全性问题,主要表示在一个Date类型的字段在进行@Getter注解时,没有检查它是否为空,这块我们有两种解决方案,第一种是手写Date类型的字段的Getter方法;第二种是安装com.google.code.findbugs:findbugs包,然后使用它的@SuppressFBWarnings注释,把这种问题忽略,我们介绍一下这两种方法。

    第一种

    重写它的setter方法

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

    第二种

    使用引用findbug包

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

    在实体上添加SuppressFBWarnings注解即可

    @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时,这个错误就没有了。

  • 相关阅读:
    python 玩转列表list
    Python入门之_水仙花数
    自兴人工智能 字符串
    自兴人工智能 元组
    自兴人工智能 列表
    自兴人工智能 python特点了解
    python走迷宫
    (自兴人工智能) python 元组
    (自兴人工智能) 玩转 python 字符串
    (自兴人工智能)Python 列表(List)的灵活使用
  • 原文地址:https://www.cnblogs.com/lori/p/13601262.html
Copyright © 2011-2022 走看看