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

  • 相关阅读:
    2.4 使用vue-cli创建项目/项目打包/发布
    2.3 vue-cli脚手架工具/nodejs
    2.2 vue的devtools、eslint检测问题
    2. es6扩展运算符
    文件json
    函数
    函数不固定参数
    监控日志,加入黑名单
    非空即真
    随机生成手机号,存入文件
  • 原文地址:https://www.cnblogs.com/lori/p/13601262.html
Copyright © 2011-2022 走看看