Merge "Ensure GitCommand's "callable" guard is thread-safe"

This commit is contained in:
Christian Halstrick 2015-01-23 02:55:06 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit e314e42d41
1 changed files with 4 additions and 3 deletions

View File

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