Skip to content

Commit 8b7c374

Browse files
authored
fix: exception when opening already opened files (JabRef#6114)
1 parent 3c0c518 commit 8b7c374

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
1515

1616
### Fixed
1717

18+
- We fixed an issue where opening a library from the recent libraries menu was not possible [#5939](https://github.com/JabRef/jabref/issues/5939)
19+
1820
### Removed
1921

2022
## [5.0] – 2020-03-06
@@ -47,7 +49,6 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
4749
- We fixed an issue where entries containing Unicode charaters were not parsed correctly [#5899](https://github.com/JabRef/jabref/issues/5899)
4850
- We fixed an issue where an entry containing an external filename with curly braces could not be saved. Curly braces are now longer allowed in filenames. [#5899](https://github.com/JabRef/jabref/issues/5899)
4951
- We fixed an issue where changing the type of an entry did not update the main table [#5906](https://github.com/JabRef/jabref/issues/5906)
50-
- We fixed an issue where opening a library from the recent libraries menu was not possible [#5939](https://github.com/JabRef/jabref/issues/5939)
5152
- We fixed an issue in the optics of the library properties, that cropped the dialog on scaled displays. [#5969](https://github.com/JabRef/jabref/issues/5969)
5253
- We fixed an issue where changing the type of an entry did not update the main table. [#5906](https://github.com/JabRef/jabref/issues/5906)
5354
- We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939)

src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.nio.file.Files;
44
import java.nio.file.Path;
55
import java.sql.SQLException;
6+
import java.util.ArrayList;
67
import java.util.Arrays;
78
import java.util.Collections;
89
import java.util.Iterator;
@@ -42,11 +43,11 @@ public class OpenDatabaseAction extends SimpleCommand {
4243
// List of actions that may need to be called after opening the file. Such as
4344
// upgrade actions etc. that may depend on the JabRef version that wrote the file:
4445
private static final List<GUIPostOpenAction> POST_OPEN_ACTIONS = Arrays.asList(
45-
// Migrations:
46-
// Warning for migrating the Review into the Comment field
47-
new MergeReviewIntoCommentAction(),
48-
// Check for new custom entry types loaded from the BIB file:
49-
new CheckForNewEntryTypesAction());
46+
// Migrations:
47+
// Warning for migrating the Review into the Comment field
48+
new MergeReviewIntoCommentAction(),
49+
// Check for new custom entry types loaded from the BIB file:
50+
new CheckForNewEntryTypesAction());
5051

5152
private final JabRefFrame frame;
5253
private final DialogService dialogService;
@@ -84,7 +85,6 @@ public void execute() {
8485
}
8586

8687
/**
87-
*
8888
* @return Path of current panel database directory or the working directory
8989
*/
9090
private Path getInitialDirectory() {
@@ -102,7 +102,7 @@ private Path getInitialDirectory() {
102102
* @param file the file, may be null or not existing
103103
*/
104104
public void openFile(Path file, boolean raisePanel) {
105-
openFiles(Arrays.asList(file), raisePanel);
105+
openFiles(new ArrayList<>(List.of(file)), raisePanel);
106106
}
107107

108108
/**
@@ -116,12 +116,12 @@ public void openFiles(List<Path> filesToOpen, boolean raisePanel) {
116116
int removed = 0;
117117

118118
// Check if any of the files are already open:
119-
for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext();) {
119+
for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext(); ) {
120120
Path file = iterator.next();
121121
for (int i = 0; i < frame.getTabbedPane().getTabs().size(); i++) {
122122
BasePanel basePanel = frame.getBasePanelAt(i);
123123
if ((basePanel.getBibDatabaseContext().getDatabasePath().isPresent())
124-
&& basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) {
124+
&& basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) {
125125
iterator.remove();
126126
removed++;
127127
// See if we removed the final one. If so, we must perhaps
@@ -169,10 +169,9 @@ private void openTheFile(Path file, boolean raisePanel) {
169169
OpenDatabaseAction.performPostOpenActions(panel, result);
170170
})
171171
.onFailure(ex -> dialogService.showErrorDialogAndWait(Localization.lang("Connection error"),
172-
ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened.")))
172+
ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened.")))
173173
.executeWith(Globals.TASK_EXECUTOR);
174174
}
175-
176175
}
177176

178177
private ParserResult loadDatabase(Path file) throws Exception {
@@ -187,23 +186,21 @@ private ParserResult loadDatabase(Path file) throws Exception {
187186
}
188187

189188
ParserResult result = OpenDatabase.loadDatabase(fileToLoad.toString(),
190-
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
189+
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
191190

192191
if (result.getDatabase().isShared()) {
193192
try {
194193
new SharedDatabaseUIManager(frame).openSharedDatabaseFromParserResult(result);
195194
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
196-
NotASharedDatabaseException e) {
195+
NotASharedDatabaseException e) {
197196
result.getDatabaseContext().clearDatabaseFile(); // do not open the original file
198197
result.getDatabase().clearSharedDatabaseID();
199198
LOGGER.error("Connection error", e);
200199

201200
throw e;
202-
203201
}
204202
}
205203
return result;
206-
207204
}
208205

209206
private BasePanel addNewDatabase(ParserResult result, final Path file, boolean raisePanel) {
@@ -214,6 +211,5 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r
214211
BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance());
215212
frame.addTab(basePanel, raisePanel);
216213
return basePanel;
217-
218214
}
219215
}

0 commit comments

Comments
 (0)