SonarQube认为我的变量在这里可以为空,而如果是这种情况则会抛出自定义异常

时间:2017-06-02 16:44:26

标签: java nullpointerexception sonarqube

private void notFoundIfNull(Object o) {
  if (o == null) {
    throw new NotFoundException();
  }
}

public int run(Object o) {
  notFoundIfNull(o);
  return o.getIndex(); // <-- NullPointerException might be thrown as 'o' is nullable here
}

有没有办法让SonarQube明白o在这里不能为空,否则会抛出NotFoundException

SonarJava v4.9.0.9858

0 个答案:

没有答案