From e7254717296440cc49bab1fcdf6cc9eaf277d3a9 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 5 Nov 2015 18:19:13 +0100 Subject: [PATCH] [platform] allow only one background decompilation, to avoid SOE --- .../openapi/fileEditor/impl/LoadTextUtil.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java b/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java index 9b9ff2e84ff1..8ba38f1410a5 100644 --- a/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java +++ b/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,6 @@ import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.*; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; @@ -359,6 +358,8 @@ public final class LoadTextUtil { return CharsetUtil.extractCharsetFromFileContent(project, virtualFile, virtualFile.getFileType(), text); } + private static boolean ourDecompileProgressStarted = false; + @NotNull public static CharSequence loadText(@NotNull final VirtualFile file) { if (file instanceof LightVirtualFile) { @@ -376,26 +377,34 @@ public final class LoadTextUtil { CharSequence text; Application app = ApplicationManager.getApplication(); - if (app != null && app.isDispatchThread() && !app.isWriteAccessAllowed() && !GraphicsEnvironment.isHeadless()) { + if (app != null && app.isDispatchThread() && !app.isWriteAccessAllowed() && !ourDecompileProgressStarted) { final Ref result = Ref.create(ArrayUtil.EMPTY_CHAR_SEQUENCE); final Ref error = Ref.create(); - ProgressManager.getInstance().run(new Task.Modal(null, "Decompiling " + file.getName(), true) { - @Override - public void run(@NotNull ProgressIndicator indicator) { - indicator.setIndeterminate(true); - try { - result.set(ApplicationUtil.runWithCheckCanceled(new Callable() { - @Override - public CharSequence call() { - return decompiler.decompile(file); - } - }, indicator)); + + ourDecompileProgressStarted = true; + try { + ProgressManager.getInstance().run(new Task.Modal(null, "Decompiling " + file.getName(), true) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + indicator.setIndeterminate(true); + try { + result.set(ApplicationUtil.runWithCheckCanceled(new Callable() { + @Override + public CharSequence call() { + return decompiler.decompile(file); + } + }, indicator)); + } + catch (Throwable t) { + error.set(t); + } } - catch (Throwable t) { - error.set(t); - } - } - }); + }); + } + finally { + ourDecompileProgressStarted = false; + } + ExceptionUtil.rethrowUnchecked(error.get()); text = result.get(); }