ExportReviewNotes: Fix synchronization on non-final field
When all error prone warnings are enabled the SynchronizeOnNonFinalField
bug pattern is reported:
plugins/reviewnotes/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java:110:
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 (changes) {
^
(see https://errorprone.info/bugpattern/SynchronizeOnNonFinalField)
Change-Id: Ie671af628f1ce60de53165048b80d88e2c4d26ae
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
index 06975a0..447cb77 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
@@ -50,6 +50,8 @@
@Inject private RetryHelper retryHelper;
+ private static final Object lock = new Object();
+
private ListMultimap<Project.NameKey, ChangeNotes> changes;
private ThreadSafeProgressMonitor monitor;
@@ -107,7 +109,7 @@
}
private Map.Entry<Project.NameKey, List<ChangeNotes>> next() {
- synchronized (changes) {
+ synchronized (lock) {
if (changes.isEmpty()) {
return null;
}