Skip to content

Commit

Permalink
Fix Copy linked files dialog showing NPE when no linked files (#3821)
Browse files Browse the repository at this point in the history
* Fix NPE with dialog showing
Fix exception when no linked file exists

* add changelog

* fix optional null to optional.empty
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Mar 8, 2018
1 parent bb471a2 commit fb5bb10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The new default removes the linked file from the entry instead of deleting the f
- We fixed an issue where not all bibtex/biblatex fields would be exported as latex-free to MS-Office XML [koppor#284](https://github.com/koppor/jabref/issues/284)
- We fixed an issue where linked files would be deleted from bibliography entries despite choosing the "Cancel" option in the dialog menu.
- We fixed the name of the group editing window to "Add group" instead of "Edit Group" when adding a new group. [koppor#277](https://github.com/koppor/jabref/issues/277)
- We fixed an issue where the "Copy linked files" dialog produced an error when the entry had no file [#3818](https://github.com/JabRef/jabref/issues/3818)

### Removed
- We removed the [Look and Feels from JGoodies](http://www.jgoodies.com/freeware/libraries/looks/), because the open source version is not compatible with Java 9.
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ public void actionPerformed(ActionEvent e) {

private void startServiceAndshowProgessDialog(Task<List<CopyFilesResultItemViewModel>> exportService) {

DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showCanceableProgressDialogAndWait(exportService));
DefaultTaskExecutor.runInJavaFXThread(() -> {
dialogService.showCanceableProgressDialogAndWait(exportService);
});

exportService.run(); //Run kinda blocks, so we just show the result dialog wgeb run is ready
DefaultTaskExecutor.runInJavaFXThread(() -> showDialog(exportService.getValue()));
exportService.run();
DefaultTaskExecutor.runInJavaFXThread(() -> {
showDialog(exportService.getValue());
});
}

private void showDialog(List<CopyFilesResultItemViewModel> data) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CopyFilesTask extends Task<List<CopyFilesResultItemViewModel>> {
private final long totalFilesCount;
private final List<BibEntry> entries;
private final List<CopyFilesResultItemViewModel> results = new ArrayList<>();
private Optional<Path> newPath;
private Optional<Path> newPath = Optional.empty();
private int numberSucessful;
private int totalFilesCounter;

Expand All @@ -54,8 +54,7 @@ public CopyFilesTask(BibDatabaseContext databaseContext, List<BibEntry> entries,
}

@Override
protected List<CopyFilesResultItemViewModel> call()
throws InterruptedException, IOException {
protected List<CopyFilesResultItemViewModel> call() throws InterruptedException, IOException {

updateMessage(Localization.lang("Copying files..."));
updateProgress(0, totalFilesCount);
Expand Down Expand Up @@ -103,6 +102,7 @@ protected List<CopyFilesResultItemViewModel> call()
}
}
updateMessage(Localization.lang("Finished copying"));

String sucessMessage = Localization.lang("Copied %0 files of %1 sucessfully to %2", Integer.toString(numberSucessful), Integer.toString(totalFilesCounter), newPath.map(Path::getParent).map(Path::toString).orElse(""));
updateMessage(sucessMessage);
bw.write(sucessMessage);
Expand Down

0 comments on commit fb5bb10

Please sign in to comment.