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;
}
謝謝,就是這樣。 –