void () { File ioRoot = new File(FileUtil.getTempDirectory()); VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioRoot); vRoot.getChildren(); Module module = createModule("a.iml"); ModuleRootModificationUtil.addContentRoot(module, vRoot.getPath()); ModuleRootModificationUtil.updateModel(module, model -> model.getContentEntries()[0].addExcludeFolder(vRoot.getUrl() + "/parent/excluded")); MessageBusConnection connect = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()); BulkFileListener rogueListenerWhichStupidlyGetChildrenRightAway = new BulkFileListener() { @Override public void after(@NotNull List<? extends @NotNull VFileEvent> events) { for (VFileEvent event : events) { VirtualFile file = event.getFile(); if (event instanceof VFileCreateEvent && file != null) { file.getChildren();// aaaaaaaaah! } } } }; connect.subscribe(VirtualFileManager.VFS_CHANGES, rogueListenerWhichStupidlyGetChildrenRightAway); myModuleRootListener.reset(); File iParent = new File(ioRoot, "parent"); assertTrue(iParent.mkdirs()); vRoot.refresh(true, true); TimeoutUtil.sleep(1000); // hope that now async refresh has found "parent" and is waiting for EDT to fire events File ioExcluded = new File(iParent, "excluded"); assertTrue(ioExcluded.mkdirs()); UIUtil.dispatchAllInvocationEvents(); // now events are fired assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioExcluded)); myModuleRootListener.assertEventsCount(1); }