Findbugs reports Loading a known null value when checking a constructor argument

When scanning the following code with findbugs, it tells Dodgy code: NP: Load the known null value into new .... (in the line where the new exception is thrown)

Sometimes, before initializing an object, you need to check the null value. Why is it considered "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;
  }
+4
source share
1 answer

I assume FindBugs indicates that the line where you selected the exception

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

equivalently

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

and wants you to use the latter. Is the first argument to this constructor EmpServiceExceptionannotated with @NonNull?

+4

Source: https://habr.com/ru/post/1611910/


All Articles