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

  • 相关阅读:
    springboot事物和事物回滚
    MyBatis Sql语句中的转义字符
    使用 vagrant新建Linux虚拟机
    Centos 6.7 安装mongodb
    阿里云windows server 2012 TIME_WAIT CLOSE_WAIT
    使用Eclipse打jar包 包含依赖jar包
    linux crontab定时器
    mysql 存储过程学习笔记
    oracle windows 新建用户授权 导出导入bmp文件
    解决hash冲突的方法
  • 原文地址:https://www.cnblogs.com/lori/p/13601262.html
Copyright © 2011-2022 走看看