Skip to content

Commit

Permalink
[JENKINS-66212] Fix null pointer exception in getLastBuildData
Browse files Browse the repository at this point in the history
Provide diagnostic logging to identify which of the previous expected
conditions are no longer valid.
  • Loading branch information
MarkEWaite committed Jul 24, 2021
1 parent 4bdad8c commit 2d78960
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/main/java/hudson/plugins/git/util/BuildData.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,63 @@ public boolean hasBeenBuilt(ObjectId sha1) {
}

public Build getLastBuild(ObjectId sha1) {
if (sha1 == null) {
LOGGER.log(Level.FINEST, "sha1 is null in getLastBuild, returning null");
return null;
}
// fast check by first checking most recent build
if (lastBuild != null && (lastBuild.revision.getSha1().equals(sha1) || lastBuild.marked.getSha1().equals(sha1))) return lastBuild;
if (lastBuild != null) {
if (lastBuild.revision != null) {
ObjectId lastBuildRevisionSha1 = lastBuild.revision.getSha1();
if (lastBuildRevisionSha1 != null) {
if (lastBuildRevisionSha1.equals(sha1)) {
LOGGER.log(Level.FINEST, "lastBuildRevisionSha1 matches sha1:" + sha1.getName() + ", returning lastBuild");
return lastBuild;
} else {
LOGGER.log(Level.FINEST, "lastBuildRevisionSha1: " + lastBuildRevisionSha1.getName() + " does not match sha1:" + sha1.getName() + ", checking lastBuild.marked");
}
} else {
LOGGER.log(Level.FINEST, "lastBuild.revision.getSha1() is null, checking lastBuild.marked");
}
} else {
LOGGER.log(Level.FINEST, "lastBuild.revision is null, checking lastBuild.marked");
}
if (lastBuild.marked != null) {
ObjectId lastBuildMarkedSha1 = lastBuild.marked.getSha1();
if (lastBuildMarkedSha1 != null) {
if (lastBuildMarkedSha1.equals(sha1)) {
LOGGER.log(Level.FINEST, "lastBuildMarkedSha1 matches sha1:" + sha1.getName() + ", returning lastBuild");
return lastBuild;
} else {
LOGGER.log(Level.FINEST, "lastBuildMarkedSha1:" + lastBuildMarkedSha1.getName() + " does not match sha1:" + sha1.getName());
}
} else {
LOGGER.log(Level.FINEST, "lastBuild.marked.getSha1() is null");
}
} else {
LOGGER.log(Level.FINEST, "lastBuild.marked is null");
}
} else {
LOGGER.log(Level.FINEST, "lastBuild is null");
}

for (Build b : buildsByBranchName.values()) {
if (b == null || b.revision == null || b.revision.getSha1() == null) {
continue;
}
if (b.revision.getSha1().equals(sha1)) {
LOGGER.log(Level.FINEST, "b.lastBuildRevisionSha1 matches sha1:" + sha1.getName() + ", returning b");
return b;
}
if (b.marked == null || b.marked.getSha1() == null) {
continue;
}
if (b.marked.getSha1().equals(sha1)) {
LOGGER.log(Level.FINEST, "b.lastBuildMarkedSha1 matches sha1:" + sha1.getName() + ", returning b");
return b;
}
}
LOGGER.log(Level.FINEST, "No match found in getLastBuild for sha1:" + sha1.getName() + ", returning null");
return null;
}

Expand Down

0 comments on commit 2d78960

Please sign in to comment.