Skip to content

Commit

Permalink
GearmanProxy: avoid NPE if a finished build has no executor
Browse files Browse the repository at this point in the history
When the build is finalized we retriever the executor/computer that ran
it to get other works to check the availability lock. Spotbugs
complains `Run.getExecutor()` might be null which really should never
happen.  If that is ever the case, throw an IllegalStateException, it
will be caught and reported by Jenkins runListener.
  • Loading branch information
hashar committed Jan 17, 2022
1 parent 595f444 commit a408cb5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/hudson/plugins/gearman/GearmanProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package hudson.plugins.gearman;

import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.Run;
import hudson.model.Queue;
Expand Down Expand Up @@ -282,8 +283,16 @@ public int getNumExecutors() {
return gmwtHandles.size() + gewtHandles.size();
}

/**
* @throws IllegalStateException If the finalized build has no executor
*/
public void onBuildFinalized(Run r) {
Computer computer = r.getExecutor().getOwner();
Executor executor = r.getExecutor();
if (executor == null) {
throw new IllegalStateException("Finalizing build " + r + " has no executor");
}

Computer computer = executor.getOwner();
// A build just finished, so let the AvailabilityMonitor
// associated with its node wake up any workers who may be
// waiting for the lock.
Expand Down

0 comments on commit a408cb5

Please sign in to comment.