diff --git a/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveManager.java b/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveManager.java index 95b7c9b3ffe..4f81cc2c0b2 100644 --- a/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveManager.java +++ b/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveManager.java @@ -44,8 +44,8 @@ private AutosaveManager(BibDatabaseContext bibDatabaseContext, CoarseChangeFilte this.executor.scheduleAtFixedRate( () -> { if (needsSave) { - eventBus.post(new AutosaveEvent()); - needsSave = false; + eventBus.post(new AutosaveEvent()); + needsSave = false; } }, DELAY_BETWEEN_AUTOSAVE_ATTEMPTS_IN_SECONDS, @@ -61,7 +61,11 @@ public void listen(@SuppressWarnings("unused") BibDatabaseContextChangedEvent ev } private void shutdown() { - coarseChangeFilter.unregisterListener(this); + try { + coarseChangeFilter.unregisterListener(this); + } catch (IllegalArgumentException e) { + // ignore exception if the listener was not registered before + } runningInstances.remove(this); } @@ -83,7 +87,7 @@ public static AutosaveManager start(BibDatabaseContext bibDatabaseContext, Coars */ public static void shutdown(BibDatabaseContext bibDatabaseContext) { runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).findAny() - .ifPresent(instance -> instance.shutdown()); + .ifPresent(AutosaveManager::shutdown); } public void registerListener(Object listener) {