Skip to content

Commit

Permalink
Merge pull request #14 from oleg-nenashev/bug/JENKINS-47574
Browse files Browse the repository at this point in the history
[JENKINS-47574] - Prevent NPE in EnvInjectAction#getEnvironment() when it's called in readResolve()
  • Loading branch information
oleg-nenashev committed Oct 24, 2017
2 parents e2d0a75 + a5da0e1 commit 7da8f74
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/jenkinsci/lib/envinject/EnvInjectAction.java
Expand Up @@ -163,13 +163,24 @@ public String transformEntry(String key, String value) {
return this;
}

@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
justification = "JENKINS-47574 - parent may be null during readResolve()")
private static boolean runHasNoParent(@Nonnull Run<?,?> run) {
return run.getParent() == null;
}

@CheckForNull
private Map<String, String> getEnvironment(@CheckForNull Run<?, ?> build) throws EnvInjectException {

if (build == null) {
return null;
}

// It happens in the case of usage of this logic for a not-fully loaded build
if (runHasNoParent(build)) {
return null;
}

EnvInjectSavable dao = new EnvInjectSavable();
return dao.getEnvironment(build.getRootDir());
}
Expand Down

0 comments on commit 7da8f74

Please sign in to comment.