4
使用findbugs扫描以下代码时,它会报告Dodgy代码:NP:在新的...中加载已知的空值(在引发新异常的行处)Findbugs报告在验证构造函数参数时加载已知的空值
有时需要在初始化对象之前检查null。 为什么这被认为是“狡猾”?
public class Employee{
@Valid
private Department dept;
@JsonCreator
public Employee(@JsonProperty(value = "department", required = true) Department aDepartment)
throws EmpServiceException{
if (aDepartment == null) {
throw new EmpServiceException(aDepartment, "Invalid Request");
}
this.dept= aDepartment;
}
谢谢,就是这样。 –