From a24d6286038d79a4d9b4aebd1cd2aec4ec352681 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 8 Jan 2018 14:43:53 +0300 Subject: [PATCH] Fix IDEA debugger exception. See #307 --- .../teavm/idea/debug/TeaVMExecutionStack.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/debug/TeaVMExecutionStack.java b/tools/idea/plugin/src/main/java/org/teavm/idea/debug/TeaVMExecutionStack.java index 3a0d0a5c2..105c5a30a 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/debug/TeaVMExecutionStack.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/debug/TeaVMExecutionStack.java @@ -15,6 +15,7 @@ */ package org.teavm.idea.debug; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; @@ -67,13 +68,17 @@ public class TeaVMExecutionStack extends XExecutionStack { @Nullable VirtualFile findVirtualFile(@NotNull String partialPath) { - Stream roots = Stream.concat( - Arrays.stream(rootManager.getContentSourceRoots()), - Arrays.stream(rootManager.orderEntries().getAllSourceRoots())); - return roots - .map(sourceRoot -> sourceRoot.findFileByRelativePath(partialPath)) - .filter(Objects::nonNull) - .findFirst() - .orElse(null); + VirtualFile[] resultHolder = new VirtualFile[1]; + ApplicationManager.getApplication().runReadAction(() -> { + Stream roots = Stream.concat( + Arrays.stream(rootManager.getContentSourceRoots()), + Arrays.stream(rootManager.orderEntries().getAllSourceRoots())); + resultHolder[0] = roots + .map(sourceRoot -> sourceRoot.findFileByRelativePath(partialPath)) + .filter(Objects::nonNull) + .findFirst() + .orElse(null); + }); + return resultHolder[0]; } }