]> source.dussan.org Git - jgit.git/commitdiff
Ensure GitCommand's "callable" guard is thread-safe 82/40082/1
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Jan 2015 22:52:28 +0000 (23:52 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Jan 2015 22:52:28 +0000 (23:52 +0100)
This way we can ensure that the same command instance can't be used
concurrently in multiple threads.

Bug: 458023
Change-Id: I4884a1ef2f609f9fb24dda4bd5819dffb9f174b6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/GitCommand.java

index 329b1b5aea148a7b5bcec1a7993171ceeb088f84..e9751f94a165b83fe116744ba15fe61091aa36e2 100644 (file)
@@ -39,6 +39,7 @@ package org.eclipse.jgit.api;
 
 import java.text.MessageFormat;
 import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.internal.JGitText;
@@ -71,7 +72,7 @@ public abstract class GitCommand<T> implements Callable<T> {
         * a state which tells whether it is allowed to call {@link #call()} on this
         * instance.
         */
-       private boolean callable = true;
+       private AtomicBoolean callable = new AtomicBoolean(true);
 
        /**
         * Creates a new command which interacts with a single repository
@@ -100,7 +101,7 @@ public abstract class GitCommand<T> implements Callable<T> {
         *            this instance.
         */
        protected void setCallable(boolean callable) {
-               this.callable = callable;
+               this.callable.set(callable);
        }
 
        /**
@@ -112,7 +113,7 @@ public abstract class GitCommand<T> implements Callable<T> {
         *             is {@code false}
         */
        protected void checkCallable() {
-               if (!callable)
+               if (!callable.get())
                        throw new IllegalStateException(MessageFormat.format(
                                        JGitText.get().commandWasCalledInTheWrongState
                                        , this.getClass().getName()));