Skip to content

Commit

Permalink
Fix NPE when opening a non existing file from the recent files menu (#…
Browse files Browse the repository at this point in the history
…5338)

* Fix NPE when opening a non existing file from the recent files menu

dialogService object was null, because the FileHistoryMenu class is initialized before the ctor of JabRef frame creates the dialog service object

* fix checkstyle

* Revert "fix checkstyle"

This reverts commit 644b1e0.

* initialize FileHistoryMenu in ctor

* pass opendatabase action instead of JabRef Frame
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Sep 21, 2019
1 parent db96f88 commit 2bd0995
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an error where the number of matched entries shown in the group pane was not updated correctly. [#4441](https://github.com/JabRef/jabref/issues/4441)
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.
- We fixed an error where a cleared search was restored after switching libraries. [#4846](https://github.com/JabRef/jabref/issues/4846)
- We fixed an exception which occured when trying to open a non existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334)


### Removed

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class JabRefFrame extends BorderPane {
private final GlobalSearchBar globalSearchBar = new GlobalSearchBar(this, Globals.stateManager);

private final ProgressBar progressBar = new ProgressBar();
private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this);
private final FileHistoryMenu fileHistory;

private final Stage mainStage;
private final StateManager stateManager;
Expand All @@ -160,6 +160,7 @@ public JabRefFrame(Stage mainStage) {
this.stateManager = Globals.stateManager;
this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager);
this.undoManager = Globals.undoManager;
this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction());
}

private static BasePanel getBasePanel(Tab tab) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/menus/FileHistoryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
import javafx.scene.control.MenuItem;

import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileHistory;
import org.jabref.preferences.JabRefPreferences;

public class FileHistoryMenu extends Menu {

private final FileHistory history;
private final JabRefFrame frame;
private final JabRefPreferences preferences;
private final DialogService dialogService;
private final OpenDatabaseAction openDatabaseAction;

public FileHistoryMenu(JabRefPreferences preferences, JabRefFrame frame) {
public FileHistoryMenu(JabRefPreferences preferences, DialogService dialogService, OpenDatabaseAction openDatabaseAction) {
setText(Localization.lang("Recent libraries"));

this.frame = frame;
this.preferences = preferences;
this.dialogService = frame.getDialogService();
this.dialogService = dialogService;
this.openDatabaseAction = openDatabaseAction;
history = preferences.getFileHistory();
if (history.isEmpty()) {
setDisable(true);
Expand Down Expand Up @@ -63,14 +63,14 @@ public void storeHistory() {

public void openFile(Path file) {
if (!Files.exists(file)) {
dialogService.showErrorDialogAndWait(
this.dialogService.showErrorDialogAndWait(
Localization.lang("File not found"),
Localization.lang("File not found") + ": " + file);
history.removeItem(file);
setItems();
return;
}
frame.getOpenDatabaseAction().openFile(file, true);
openDatabaseAction.openFile(file, true);

}

Expand Down

0 comments on commit 2bd0995

Please sign in to comment.