Findbugs 在验证构造函数参数时报告加载已知空值

Findbugs reports Load of known null value while validating constructor argument

使用 findbugs 扫描以下代码后,它报告 Dodgy code:NP: Load of known null value in new ....(在抛出新异常的行)

有时需要在初始化对象之前检查空值。 为什么这被认为是 "dodgy"??

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;
  }

我的猜测是 FindBugs 指出您抛出异常的行

throw new EmpServiceException(aDepartment, "Invalid Request");

等同于

throw new EmpServiceException(null, "Invalid Request");

并希望您使用后者。 EmpServiceException 构造函数的第一个参数是否用 @NonNull 注释?