# Is this the correct way of opening a file in the editor

**URL:** <https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065>\
**Category:** IntelliJ Platform\
**Created:** [March 24, 2025, 10:22am UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065 "2025-03-24T10:22:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kinae](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@Kinae](https://platform.jetbrains.com/u/Kinae)\
**Post date:** [March 24, 2025, 10:22am UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065/1 "2025-03-24T10:22:58Z")

</div>

Hi everyone !

I am experiencing a strange behaviour, I am developing a plugin and while I need to open a file located in the plugin directory I get : `Slow operations are prohibited on EDT`

I am wondering if this is the right way of doing it :

```auto
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(bookmarkFile.path());
if (virtualFile != null) {
  ApplicationManager.getApplication().runReadAction(() -> {
    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
    FileEditorManager.getInstance(project).openEditor(descriptor, false);
  });
}

```

The plugin works, I do not get that error a lot, it’s from time to time.  
I tried without the ` ApplicationManager.getApplication().runReadAction(() -> {` but the same, I am running out of options (I tried the `invokeLater` too) because this is needed to be run on EDT at the end.

I would really appreciate any kind of help 😀

Thank you

2025-03-24 11:00:55,627 [43703] SEVERE - #c.i.u.SlowOperations - IntelliJ IDEA 2023.3.8 Build #IC-233.15619.7  
2025-03-24 11:00:55,627 [43703] SEVERE - #c.i.u.SlowOperations - JDK: 17.0.12; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.  
2025-03-24 11:00:55,627 [43703] SEVERE - #c.i.u.SlowOperations - OS: Mac OS X

---

<div class="post-metadata">

**Author:** ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)\
**Post date:** [March 24, 2025, 10:48am UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065/2 "2025-03-24T10:48:22Z")

</div>

`.findFileByPath()` traverses the virtual file system, which is [considered “slow”](https://plugins.jetbrains.com/docs/intellij/threading-model.html#don-t-perform-long-operations-on-edt) and thus should not be done in EDT. You need to switch to BGT first.

In my plugin, I do this (the actual code can be found [here](https://github.com/InSyncWithFoo/ryecharm/blob/6b10c287da1fb5daf37a55afd6409d9f46ded40b/src/main/kotlin/insyncwithfoo/ryecharm/rye/actions/OpenConfigurationFile.kt#L62-L68)):

```kotlin
@Service(Service.Level.PROJECT)
class CoroutineService(override val scope: CoroutineScope)

project.service<CoroutineService>().scope.launch {
    val virtualFile = withBackgroundProgress(project, indicatorTitle, cancellable = true) {
        LocalFileSystem.getInstance().findFileByPath(somePath)
    }

    withContext(Dispatchers.EDT) {
        FileEditorManager.getInstance(project).openEditor(virtualFile!!, false)
    }
}

```

I’m not sure what the equivalent Java code would be though.

---

<div class="post-metadata">

**Author:** ![Kinae](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@Kinae](https://platform.jetbrains.com/u/Kinae)\
**Post date:** [March 24, 2025, 3:48pm UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065/3 "2025-03-24T15:48:31Z")

</div>

Thank you very much !  
The Java code is now looking like this :

```auto
ApplicationManager.getApplication().executeOnPooledThread(() -> {
    VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(bookmarkFile.path());
    if (virtualFile != null) {
        ApplicationManager.getApplication().invokeLater(() -> {
            if(!project.isDisposed()) {
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                FileEditorManager.getInstance(project).openEditor(descriptor, false);
            }
        });
     }
});

```

But still get the error pointing (mostly when starting the project and the first time I invoke the code, it does not appear to do that later. Maybe because it does not have enough ressource ?

```auto
FileEditorManager.getInstance(project).openEditor(descriptor, false);

```

---

<div class="post-metadata">

**Author:** ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)\
**Post date:** [March 24, 2025, 4:11pm UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065/4 "2025-03-24T16:11:25Z")

</div>

> […] mostly when starting the project and the first time I invoke the code, it does not appear to do that later.

This is a log-only error. If I recall correctly, it is reported once per IDE session.

As for why your code still doesn’t work, I’m not sure; I have never written threading code in Java.

---

<div class="post-metadata">

**Author:** ![Kinae](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@Kinae](https://platform.jetbrains.com/u/Kinae)\
**Post date:** [March 24, 2025, 4:24pm UTC](https://platform.jetbrains.com/t/is-this-the-correct-way-of-opening-a-file-in-the-editor/1065/5 "2025-03-24T16:24:38Z")

</div>

I will try to do that class in Kotlin and see if it’s better based on what you provided.

Thank you again !
