diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 34c8d3010ff2..ea2dad771bd5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -489,15 +489,18 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da public static void checkEditorsReleased() { // don't use method references here to make stack trace reading easier //noinspection Convert2MethodRef - RunAll runAll = new RunAll(() -> UIUtil.dispatchAllInvocationEvents()); - for (Editor editor : EditorFactory.getInstance().getAllEditors()) { - runAll = runAll - .append( - () -> EditorFactoryImpl.throwNotReleasedError(editor), - () -> EditorFactory.getInstance().releaseEditor(editor) - ); - } - runAll.run(); + new RunAll( + () -> UIUtil.dispatchAllInvocationEvents(), + () -> { + // getAllEditors() should be called only after dispatchAllInvocationEvents(), that's why separate RunAll is used + RunAll runAll = new RunAll(); + for (Editor editor : EditorFactory.getInstance().getAllEditors()) { + runAll = runAll + .append(() -> EditorFactoryImpl.throwNotReleasedError(editor)) + .append(() -> EditorFactory.getInstance().releaseEditor(editor)); + } + runAll.run(); + }).run(); } @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/RunAll.java b/platform/testFramework/src/com/intellij/testFramework/RunAll.java index b830de6b25ef..0ebba4956859 100644 --- a/platform/testFramework/src/com/intellij/testFramework/RunAll.java +++ b/platform/testFramework/src/com/intellij/testFramework/RunAll.java @@ -9,6 +9,7 @@ import com.intellij.util.lang.CompoundRuntimeException; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; /** @@ -31,7 +32,7 @@ public class RunAll implements Runnable { @SafeVarargs @Contract(pure=true) public final RunAll append(@NotNull ThrowableRunnable... actions) { - return new RunAll(ContainerUtil.concat(myActions, ContainerUtilRt.newArrayList(actions))); + return new RunAll(ContainerUtil.concat(myActions, actions.length == 1 ? Collections.singletonList(actions[0]) : ContainerUtilRt.newArrayList(actions))); } @Override