我有课
class SomeClass{
}
以及其中的静态嵌套类:
@Data
public static class CrmOpioLogFilter {
private Date fromDate;
private Date toDate;
private List<String> filterCrmGroupIds;
private String msisdn;
private List<CrmUser> crmUsers;
private List<OperationType> operationTypes;
private List<OpioLogState> states;
}
并找到错误并说错误:
Should SomeClass$CrmOpioLogFilter be a _static_ inner class?
Should be a static inner class This class is an inner class, but does not use its embedded reference to the object which created it. This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary. If possible, the class should be made static.
并显示这一行:
1 @Data
2 private Date fromDate;
3 private Date toDate;
我知道日期是可变的并重写类:
@Data
public static class CrmOpioLogFilter {
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
private Date fromDate;
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
private Date toDate;
private List<String> filterCrmGroupIds;
private String msisdn;
private List<CrmUser> crmUsers;
private List<OperationType> operationTypes;
private List<OpioLogState> states;
public void setFromDate(Date fromDate) {
this.fromDate = new Date(fromDate.getTime());
}
public void setToDate(Date toDate) {
this.toDate = new Date(toDate.getTime());
}
public Date getFromDate() {
return new Date(fromDate.getTime());
}
public Date getToDate() {
return new Date(toDate.getTime());
}
}
但 findbug 显示错误并不重要。
最佳答案
我认为这里有两个选择:
A) Lombok 创建了无效的字节码,那么 findbugs 是正确的
B) findbugs 给你一个无效的警告
您现在可以使用 javap 反汇编您的类以识别罪魁祸首。然后更深入地研究文档,或者为该工具编写错误报告。
关于java - 应该是一个静态内部类,在 Lombok @Data 内部类上找到 bug 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43579427/