Findbugs `NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE`

Findbugs `NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE`

在尝试发布 jenkins 插件时,maven 报告了一些我不知道如何修复的 findbugs 错误。

[INFO] Possible null pointer dereference in com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl.doFillAuthTokenCredentialIdItems() due to return value of called method [com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl, com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl] Dereferenced at VaultBuildWrapper.java:[line 326]Known null at VaultBuildWrapper.java:[line 326] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
[INFO] Possible null pointer dereference in com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl.doFillAuthTokenCredentialIdItems() due to return value of called method [com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl, com.datapipe.jenkins.vault.VaultBuildWrapper$DescriptorImpl] Method invoked at VaultBuildWrapper.java:[line 329]Known null at VaultBuildWrapper.java:[line 329] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

有问题的行属于以下函数:

public ListBoxModel doFillAuthTokenCredentialIdItems(){
  if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
    return new ListBoxModel();
  }
  AbstractIdCredentialsListBoxModel model = new StandardListBoxModel().includeEmptyValue().includeAs(ACL.SYSTEM, Jenkins.getInstance(), VaultTokenCredential.class);
  return model;
}

我已尝试添加以下空检查但无济于事:

public ListBoxModel doFillAuthTokenCredentialIdItems(){
  Jenkins jenkins = Jenkins.getInstance();

  if (jenkins == null) {
    return new ListBoxModel();
  }

  if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
    return new ListBoxModel();
  }
  AbstractIdCredentialsListBoxModel model = new StandardListBoxModel().includeEmptyValue().includeAs(ACL.SYSTEM, jenkins, VaultTokenCredential.class);
  return model;
}

提前致谢

不知道为什么,但在返回之前创建新的 ListBoxModel 就成功了。

public ListBoxModel doFillAuthTokenCredentialIdItems() {
  final ListBoxModel lbm = new ListBoxModel();
  final Jenkins jenkins = Jenkins.getInstance();

  if (jenkins == null) {
    return lbm;
  }

  if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
    return lbm;
  }
  AbstractIdCredentialsListBoxModel model = new StandardListBoxModel().includeEmptyValue().includeAs(ACL.SYSTEM, jenkins, VaultTokenCredential.class);
  return model;
}