Skip to content

Commit

Permalink
Merge pull request #2569 from stephenc/jenkins-38534
Browse files Browse the repository at this point in the history
[FIXED JENKINS-38534] Isolate the code that requires the `Jenkins` class to be loaded from an agent code path
  • Loading branch information
daniel-beck committed Sep 27, 2016
2 parents 96ec7a2 + 0859573 commit 31ab674
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions core/src/main/java/hudson/util/ProcessKillingVeto.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.util;

import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.util.ProcessTreeRemoting.IOSProcess;

Expand All @@ -32,7 +33,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import jenkins.model.Jenkins;
import jenkins.util.JenkinsJVM;

/**
* Allows extensions to veto killing processes. If at least one extension vetoes
Expand Down Expand Up @@ -74,11 +75,20 @@ public VetoCause(@Nonnull String message) {
* list if Jenkins is not available, never null.
*/
public static List<ProcessKillingVeto> all() {
// check if we are a thread running on the master JVM or a thread running in a remote JVM
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null)
return Collections.emptyList(); // we are remote, no body gets to veto
return jenkins.getExtensionList(ProcessKillingVeto.class);
if (JenkinsJVM.isJenkinsJVM()) {
return _all();
}
return Collections.emptyList();
}

/**
* As classloading is lazy, the classes referenced in this method will not be resolved
* until the first time the method is invoked, so we use this method to guard access to Jenkins JVM only classes.
*
* @return All ProcessKillingVeto extensions currently registered.
*/
private static List<ProcessKillingVeto> _all() {
return ExtensionList.lookup(ProcessKillingVeto.class);
}

/**
Expand Down

0 comments on commit 31ab674

Please sign in to comment.