Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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