summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@collab.net>2019-05-27 14:07:04 +0900
committerDavid Pursehouse <dpursehouse@collab.net>2019-07-17 13:34:40 +0900
commit95dc833b63a1629608c64e343ab07fa6cafc84a9 (patch)
treeb8380cd9510640272d5c1a8408148edb3ba15e7e
parent404e5069adbdf7d9ab17b887894842ad3638042d (diff)
StartCommand: Fix synchronization on non-final field
When all error prone warnings are enabled the SynchronizeOnNonFinalField bug pattern is reported: plugins/replication/src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java:103: error: [SynchronizeOnNonFinalField] Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects. synchronized (stdout) { ^ (see https://errorprone.info/bugpattern/SynchronizeOnNonFinalField) Change-Id: Ib2df20aa28af4edd36ce5b9dfcf7d82c409dab84
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java b/src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java
index 5aa0861..7115d5b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/StartCommand.java
@@ -51,6 +51,8 @@ final class StartCommand extends SshCommand {
@Inject private PushAll.Factory pushFactory;
+ private final Object lock = new Object();
+
@Override
protected void run() throws Failure {
if (all && projectPatterns.size() > 0) {
@@ -98,7 +100,7 @@ final class StartCommand extends SshCommand {
public void writeStdOutSync(String message) {
if (wait) {
- synchronized (stdout) {
+ synchronized (lock) {
stdout.println(message);
stdout.flush();
}
@@ -107,7 +109,7 @@ final class StartCommand extends SshCommand {
public void writeStdErrSync(String message) {
if (wait) {
- synchronized (stderr) {
+ synchronized (lock) {
stderr.println(message);
stderr.flush();
}