Skip to content

Commit f404793

Browse files
committed
Merge remote-tracking branch 'upstream/main' into jackson3
* upstream/main: Fix NPE on startup (#14272)
2 parents b4aaae4 + d33df95 commit f404793

File tree

4 files changed

+109
-92
lines changed

4 files changed

+109
-92
lines changed

jabgui/src/main/java/org/jabref/Launcher.java

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.nio.file.Path;
88
import java.util.Arrays;
99
import java.util.List;
10-
import java.util.Map;
1110

1211
import org.jabref.cli.ArgumentProcessor;
1312
import org.jabref.gui.JabRefGUI;
@@ -51,51 +50,56 @@ public enum MultipleInstanceAction {
5150
}
5251

5352
public static void main(String[] args) {
54-
initLogging(args);
55-
56-
Injector.setModelOrService(BuildInfo.class, new BuildInfo());
57-
58-
final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance();
59-
60-
ArgumentProcessor argumentProcessor = new ArgumentProcessor(
61-
args,
62-
ArgumentProcessor.Mode.INITIAL_START,
63-
preferences);
53+
try {
54+
initLogging(args);
55+
56+
Injector.setModelOrService(BuildInfo.class, new BuildInfo());
57+
58+
final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance();
59+
60+
ArgumentProcessor argumentProcessor = new ArgumentProcessor(
61+
args,
62+
ArgumentProcessor.Mode.INITIAL_START,
63+
preferences);
64+
65+
if (!argumentProcessor.getGuiCli().usageHelpRequested) {
66+
Injector.setModelOrService(CliPreferences.class, preferences);
67+
Injector.setModelOrService(GuiPreferences.class, preferences);
68+
69+
// Early exit in case another instance is already running
70+
MultipleInstanceAction instanceAction = handleMultipleAppInstances(args, preferences.getRemotePreferences());
71+
if (instanceAction == MultipleInstanceAction.SHUTDOWN) {
72+
systemExit();
73+
} else if (instanceAction == MultipleInstanceAction.FOCUS) {
74+
// Send focus command to running instance
75+
RemotePreferences remotePreferences = preferences.getRemotePreferences();
76+
RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort());
77+
remoteClient.sendFocus();
78+
systemExit();
79+
}
6480

65-
if (!argumentProcessor.getGuiCli().usageHelpRequested) {
66-
Injector.setModelOrService(CliPreferences.class, preferences);
67-
Injector.setModelOrService(GuiPreferences.class, preferences);
81+
configureProxy(preferences.getProxyPreferences());
82+
configureSSL(preferences.getSSLPreferences());
83+
}
6884

69-
// Early exit in case another instance is already running
70-
MultipleInstanceAction instanceAction = handleMultipleAppInstances(args, preferences.getRemotePreferences());
71-
if (instanceAction == MultipleInstanceAction.SHUTDOWN) {
72-
systemExit();
73-
} else if (instanceAction == MultipleInstanceAction.FOCUS) {
74-
// Send focus command to running instance
75-
RemotePreferences remotePreferences = preferences.getRemotePreferences();
76-
RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort());
77-
remoteClient.sendFocus();
85+
List<UiCommand> uiCommands = argumentProcessor.processArguments();
86+
if (argumentProcessor.shouldShutDown()) {
7887
systemExit();
7988
}
8089

81-
configureProxy(preferences.getProxyPreferences());
82-
configureSSL(preferences.getSSLPreferences());
83-
}
84-
85-
List<UiCommand> uiCommands = argumentProcessor.processArguments();
86-
if (argumentProcessor.shouldShutDown()) {
87-
systemExit();
88-
}
89-
90-
PreferencesMigrations.runMigrations(preferences);
90+
PreferencesMigrations.runMigrations(preferences);
9191

92-
PostgreServer postgreServer = new PostgreServer();
93-
Injector.setModelOrService(PostgreServer.class, postgreServer);
92+
PostgreServer postgreServer = new PostgreServer();
93+
Injector.setModelOrService(PostgreServer.class, postgreServer);
9494

95-
CSLStyleLoader.loadInternalStyles();
95+
CSLStyleLoader.loadInternalStyles();
9696

97-
JabRefGUI.setup(uiCommands, preferences);
98-
JabRefGUI.launch(JabRefGUI.class, args);
97+
JabRefGUI.setup(uiCommands, preferences);
98+
JabRefGUI.launch(JabRefGUI.class, args);
99+
} catch (Throwable throwable) {
100+
LOGGER.error("Could not launch JabRef", throwable);
101+
throw throwable;
102+
}
99103
}
100104

101105
/**
@@ -126,16 +130,15 @@ public static void initLogging(String[] args) {
126130

127131
// The "Shared File Writer" is explained at
128132
// https://tinylog.org/v2/configuration/#shared-file-writer
129-
Map<String, String> configuration = Map.of(
130-
"level", logLevel.name().toLowerCase(),
131-
"writerFile", "rolling file",
132-
"writerFile.level", logLevel.name().toLowerCase(),
133-
// We need to manually join the path, because ".resolve" does not work on Windows, because ":" is not allowed in file names on Windows
134-
"writerFile.file", directory + File.separator + "log_{date:yyyy-MM-dd_HH-mm-ss}.txt",
135-
"writerFile.charset", "UTF-8",
136-
"writerFile.policies", "startup",
137-
"writerFile.backups", "30");
138-
configuration.forEach(Configuration::set);
133+
Configuration.set("level", logLevel.name().toLowerCase());
134+
Configuration.set("writerFile", "rolling file");
135+
Configuration.set("writerFile.level", logLevel.name().toLowerCase());
136+
// We need to manually join the path, because ".resolve" does not work on Windows,
137+
// because ":" is not allowed in file names on Windows
138+
Configuration.set("writerFile.file", directory + File.separator + "log_{date:yyyy-MM-dd_HH-mm-ss}.txt");
139+
Configuration.set("writerFile.charset", "UTF-8");
140+
Configuration.set("writerFile.policies", "startup");
141+
Configuration.set("writerFile.backups", "30");
139142

140143
LOGGER = LoggerFactory.getLogger(Launcher.class);
141144
}

jabgui/src/main/java/org/jabref/gui/JabRefGUI.java

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,52 +101,57 @@ public static void setup(List<UiCommand> uiCommands,
101101

102102
@Override
103103
public void start(Stage stage) {
104-
this.mainStage = stage;
105-
Injector.setModelOrService(Stage.class, mainStage);
104+
try {
105+
this.mainStage = stage;
106+
Injector.setModelOrService(Stage.class, mainStage);
107+
108+
initialize();
109+
110+
JabRefGUI.mainFrame = new JabRefFrame(
111+
mainStage,
112+
dialogService,
113+
fileUpdateMonitor,
114+
preferences,
115+
aiService,
116+
stateManager,
117+
countingUndoManager,
118+
Injector.instantiateModelOrService(BibEntryTypesManager.class),
119+
clipBoardManager,
120+
taskExecutor,
121+
gitHandlerRegistry);
122+
123+
openWindow();
124+
125+
startBackgroundTasks();
126+
127+
if (!fileUpdateMonitor.isActive()) {
128+
dialogService.showErrorDialogAndWait(
129+
Localization.lang("Unable to monitor file changes. Please close files " +
130+
"and processes and restart. You may encounter errors if you continue " +
131+
"with this session."));
132+
}
133+
134+
BuildInfo buildInfo = Injector.instantiateModelOrService(BuildInfo.class);
135+
EasyBind.subscribe(preferences.getInternalPreferences().versionCheckEnabledProperty(), enabled -> {
136+
if (enabled) {
137+
new VersionWorker(buildInfo.version,
138+
dialogService,
139+
taskExecutor,
140+
preferences)
141+
.checkForNewVersionDelayed();
142+
}
143+
});
144+
145+
setupProxy();
146+
} catch (Throwable throwable) {
147+
LOGGER.error("Error during initialization", throwable);
148+
throw throwable;
149+
}
106150

107151
FallbackExceptionHandler.installExceptionHandler((exception, thread) -> UiTaskExecutor.runInJavaFXThread(() -> {
108152
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
109153
dialogService.showErrorDialogAndWait("Uncaught exception occurred in " + thread, exception);
110154
}));
111-
112-
initialize();
113-
114-
JabRefGUI.mainFrame = new JabRefFrame(
115-
mainStage,
116-
dialogService,
117-
fileUpdateMonitor,
118-
preferences,
119-
aiService,
120-
stateManager,
121-
countingUndoManager,
122-
Injector.instantiateModelOrService(BibEntryTypesManager.class),
123-
clipBoardManager,
124-
taskExecutor,
125-
gitHandlerRegistry);
126-
127-
openWindow();
128-
129-
startBackgroundTasks();
130-
131-
if (!fileUpdateMonitor.isActive()) {
132-
dialogService.showErrorDialogAndWait(
133-
Localization.lang("Unable to monitor file changes. Please close files " +
134-
"and processes and restart. You may encounter errors if you continue " +
135-
"with this session."));
136-
}
137-
138-
BuildInfo buildInfo = Injector.instantiateModelOrService(BuildInfo.class);
139-
EasyBind.subscribe(preferences.getInternalPreferences().versionCheckEnabledProperty(), enabled -> {
140-
if (enabled) {
141-
new VersionWorker(buildInfo.version,
142-
dialogService,
143-
taskExecutor,
144-
preferences)
145-
.checkForNewVersionDelayed();
146-
}
147-
});
148-
149-
setupProxy();
150155
}
151156

152157
public void initialize() {

jabgui/src/main/java/org/jabref/gui/newentry/NewEntryView.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.tobiasdiez.easybind.EasyBind;
7373
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
7474
import jakarta.inject.Inject;
75+
import org.jspecify.annotations.NonNull;
7576

7677
public class NewEntryView extends BaseDialog<BibEntry> {
7778
private static final String BIBTEX_REGEX = "^@([A-Za-z]+)\\{,";
@@ -590,13 +591,14 @@ private static IdBasedFetcher fetcherFromName(String fetcherName, List<IdBasedFe
590591
return null;
591592
}
592593

593-
private static PlainCitationParserChoice parserFromName(String parserName, List<PlainCitationParserChoice> parsers) {
594+
private static @NonNull PlainCitationParserChoice parserFromName(String parserName, List<PlainCitationParserChoice> parsers) {
594595
for (PlainCitationParserChoice parser : parsers) {
595596
if (parser.getLocalizedName().equals(parserName)) {
596597
return parser;
597598
}
598599
}
599-
return null;
600+
// If nothing could be mapped, return the default - set at {@link org.jabref.gui.preferences.JabRefGuiPreferences.JabRefGuiPreferences}
601+
return PlainCitationParserChoice.RULE_BASED_GENERAL;
600602
}
601603

602604
private Optional<Identifier> extractValidIdentifierFromClipboard() {

jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,13 @@ public ImporterPreferences getImporterPreferences() {
22122212
return importerPreferences;
22132213
}
22142214

2215+
PlainCitationParserChoice defaultPlainCitationParser;
2216+
try {
2217+
defaultPlainCitationParser = PlainCitationParserChoice.valueOf(get(DEFAULT_PLAIN_CITATION_PARSER));
2218+
} catch (IllegalArgumentException ex) {
2219+
defaultPlainCitationParser = PlainCitationParserChoice.RULE_BASED_GENERAL;
2220+
}
2221+
22152222
importerPreferences = new ImporterPreferences(
22162223
getBoolean(IMPORTERS_ENABLED),
22172224
getBoolean(GENERATE_KEY_ON_IMPORT),
@@ -2222,7 +2229,7 @@ public ImporterPreferences getImporterPreferences() {
22222229
getDefaultFetcherKeys(),
22232230
getBoolean(FETCHER_CUSTOM_KEY_PERSIST),
22242231
getStringList(SEARCH_CATALOGS),
2225-
PlainCitationParserChoice.valueOf(get(DEFAULT_PLAIN_CITATION_PARSER)),
2232+
defaultPlainCitationParser,
22262233
getInt(CITATIONS_RELATIONS_STORE_TTL)
22272234
);
22282235

0 commit comments

Comments
 (0)