From ea0de1dc5ef82ab574a2bad52559372db0e1bab4 Mon Sep 17 00:00:00 2001 From: mindless Date: Tue, 6 Jan 2009 00:25:24 +0000 Subject: [PATCH] [FIXED HUDSON-2786] Fix posting external job results. Made Executor.currentExecutor() return null if current thread is not an executor, and Computer.currentComputer() return Hudson.getInstance().toComputer() if currentExecutor returns null (must be on master if not in an executor). This avoids exception causing posting of external job results to fail. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14176 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Computer.java | 4 +++- core/src/main/java/hudson/model/Executor.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 84c55e8025..d1a8827239 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -521,7 +521,9 @@ public abstract class Computer extends AbstractModelObject implements AccessCont * {@link Publisher}, {@link BuildWrapper}, etc. */ public static Computer currentComputer() { - return Executor.currentExecutor().getOwner(); + Executor e = Executor.currentExecutor(); + // If no executor then must be on master node + return e != null ? e.getOwner() : Hudson.getInstance().toComputer(); } /** diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java index 8ededd42ce..0afc34763b 100644 --- a/core/src/main/java/hudson/model/Executor.java +++ b/core/src/main/java/hudson/model/Executor.java @@ -288,10 +288,11 @@ public class Executor extends Thread implements ModelObject { } /** - * Returns the executor of the current thread. + * Returns the executor of the current thread or null if current thread is not an executor. */ public static Executor currentExecutor() { - return (Executor)Thread.currentThread(); + Thread t = Thread.currentThread(); + return t instanceof Executor ? (Executor)t : null; } private static final Logger LOGGER = Logger.getLogger(Executor.class.getName());