void (@NotNull Project project, @NotNull VirtualFile file, @NotNull List<? extends LibraryOrderEntry> originalLibraries, @NotNull Consumer<? super List<? extends LibraryOrderEntry>> uiThreadAction) { ReadAction.nonBlocking(() -> { List<? extends LibraryOrderEntry> libraries = findLibraryEntriesForFile(file, project); if (Comparing.equal(originalLibraries, libraries)) { return libraries; } throw new RuntimeException(JavaUiBundle.message("can.t.find.library.for.0", file.getName())); }) .expireWith(project) .expireWhen(() -> !file.isValid()) .coalesceBy(file, project) .finishOnUiThread(ModalityState.current(), uiThreadAction) .submit(NonUrgentExecutor.getInstance()) .onError(rejected -> { if (rejected instanceof CancellationException) { return; } SwingUtilities.invokeLater(() -> { Messages.showErrorDialog(project, rejected.getLocalizedMessage(), CommonBundle.message("title.error")); }); }); }