Skip to content
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
3 changes: 3 additions & 0 deletions jabgui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ jacoco {
*/

tasks.named<JavaExec>("run") {
// "assert" statements in the code should activated when running using gradle
enableAssertions = true

doFirst {
// Clear the default JVM arguments to avoid warnings
// application.applicationDefaultJvmArgs = emptyList()
Expand Down
1 change: 1 addition & 0 deletions jabgui/src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void initialize() {
WebViewStore.init();

DefaultFileUpdateMonitor fileUpdateMonitor = new DefaultFileUpdateMonitor();
this.fileUpdateMonitor = fileUpdateMonitor;
HeadlessExecutorService.INSTANCE.executeInterruptableTask(fileUpdateMonitor, "FileUpdateMonitor");
Injector.setModelOrService(FileUpdateMonitor.class, fileUpdateMonitor);

Expand Down
2 changes: 2 additions & 0 deletions jabgui/src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private LibraryTab(BibDatabaseContext bibDatabaseContext,
this.dialogService = dialogService;
this.preferences = Objects.requireNonNull(preferences);
this.stateManager = Objects.requireNonNull(stateManager);
assert bibDatabaseContext.getDatabasePath().isEmpty() || fileUpdateMonitor != null;
this.fileUpdateMonitor = fileUpdateMonitor;
this.entryTypesManager = entryTypesManager;
this.clipBoardManager = clipBoardManager;
Expand Down Expand Up @@ -751,6 +752,7 @@ public FileAnnotationCache getAnnotationCache() {

public void resetChangeMonitor() {
changeMonitor.ifPresent(DatabaseChangeMonitor::unregister);
assert bibDatabaseContext.getDatabasePath().isEmpty() || fileUpdateMonitor != null;
changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext,
fileUpdateMonitor,
taskExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public void openFiles(List<Path> filesToOpen) {
// Run the actual open in a thread to prevent the program
// locking until the file is loaded.
if (!filesToOpen.isEmpty()) {
assert fileUpdateMonitor != null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assertions for null checks is not recommended for production code as they can be disabled. Consider using JSpecify @nonnull annotations for better null safety.

FileHistory fileHistory = preferences.getLastFilesOpenedPreferences().getFileHistory();
filesToOpen.forEach(theFile -> {
// This method will execute the concrete file opening and loading in a background thread
Expand Down Expand Up @@ -224,6 +225,8 @@ private void openTheFile(Path file) {
return;
}

assert fileUpdateMonitor != null;

BackgroundTask<ParserResult> backgroundTask = BackgroundTask.wrap(() -> loadDatabase(file));
// The backgroundTask is executed within the method createLibraryTab
LibraryTab newTab = LibraryTab.createLibraryTab(
Expand Down