From a1862621138a218ca3ec4c304fa3fc47364c26d8 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 3 Feb 2015 16:57:14 +0100 Subject: [PATCH] Do not use two volatiles to hold state that needs to be atomically updated --- core/src/main/java/hudson/model/Computer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 5ffed29031..2d31b410c1 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -168,7 +168,6 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces * @see #getEnvironment() */ private volatile EnvVars cachedEnvironment; - private volatile boolean environmentCached; private final WorkspaceList workspaceList = new WorkspaceList(); @@ -346,7 +345,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces * make much sense because as soon as {@link Computer} is connected it can be disconnected by some other threads.) */ public final Future connect(boolean forceReconnect) { - environmentCached = false; + this.cachedEnvironment = null; connectTime = System.currentTimeMillis(); return _connect(forceReconnect); } @@ -947,12 +946,13 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces * If this is the master, it returns the system property of the master computer. */ public EnvVars getEnvironment() throws IOException, InterruptedException { - if (environmentCached) { + EnvVars cachedEnvironment = this.cachedEnvironment; + if (cachedEnvironment != null) { return cachedEnvironment; } cachedEnvironment = EnvVars.getRemote(getChannel()); - environmentCached = true; + this.cachedEnvironment = cachedEnvironment; return cachedEnvironment; } -- GitLab