void (VirtualFilePointer pointer, Collection<? super Job<?>> reads) { for (int i = 0; i < 10; i++) { AtomicReference<Job<?>> reference = new AtomicReference<>(); reference.set(JobLauncher.getInstance().submitToJobThread(() -> ApplicationManager.getApplication().runReadAction(() -> { VirtualFile file = pointer.getFile(); if (file != null && !file.isValid()) { throw new IncorrectOperationException("I've caught it. I am that good"); } }), future -> { try { future.get(); } catch (Exception e) { throw new RuntimeException(e); } finally { reads.remove(reference.get()); } })); reads.add(reference.get()); } }