Skip to content

Commit

Permalink
fix: address issues with concurrency in DefaultFileUpdateMonitor (Jab…
Browse files Browse the repository at this point in the history
…Ref#10585)

Changed the MultiMap into a synchronized type for safety

Used the Platform.runLater() to ensure processes are executed on correct threads

Not sure what the side effects of these fixes are
  • Loading branch information
VinterSallad committed Feb 28, 2024
1 parent 426b0bf commit c2370b8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import javafx.application.Platform;

import org.jabref.logic.JabRefException;
import org.jabref.logic.WatchServiceUnavailableException;
import org.jabref.model.util.FileUpdateListener;
import org.jabref.model.util.FileUpdateMonitor;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +35,7 @@ public class DefaultFileUpdateMonitor implements Runnable, FileUpdateMonitor {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFileUpdateMonitor.class);

private final Multimap<Path, FileUpdateListener> listeners = ArrayListMultimap.create(20, 4);
private final Multimap<Path, FileUpdateListener> listeners = Multimaps.synchronizedListMultimap(ArrayListMultimap.create(20, 4));
private volatile WatchService watcher;
private final AtomicBoolean notShutdown = new AtomicBoolean(true);
private final AtomicReference<Optional<JabRefException>> filesystemMonitorFailure = new AtomicReference<>(Optional.empty());
Expand Down Expand Up @@ -82,7 +85,7 @@ public boolean isActive() {
}

private void notifyAboutChange(Path path) {
listeners.get(path).forEach(FileUpdateListener::fileUpdated);
Platform.runLater(() -> listeners.get(path).forEach(FileUpdateListener::fileUpdated));
}

@Override
Expand Down

0 comments on commit c2370b8

Please sign in to comment.