diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt index cb7fc5b7633..2095dc46edf 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt @@ -36,28 +36,33 @@ import java.util.jar.Manifest class KotlinDecompilerServiceImpl : KotlinDecompilerService { override fun decompile(file: KtFile): String? { - val bytecodeMap = when { - file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile) - !file.isCompiled -> bytecodeMapForSourceFile(file) - else -> return null - } - val resultSaver = KotlinResultSaver() - val options = hashMapOf( - IFernflowerPreferences.REMOVE_BRIDGE to "0" - ) + try { + val bytecodeMap = when { + file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile) + !file.isCompiled -> bytecodeMapForSourceFile(file) + else -> return null + } + val resultSaver = KotlinResultSaver() + val options = hashMapOf( + IFernflowerPreferences.REMOVE_BRIDGE to "0" + ) - val bytecodeProvider = IBytecodeProvider { - externalPath, _ -> - val path = File(FileUtil.toSystemIndependentName(externalPath)) - bytecodeMap[path]?.invoke() - } + val bytecodeProvider = IBytecodeProvider { + externalPath, _ -> + val path = File(FileUtil.toSystemIndependentName(externalPath)) + bytecodeMap[path]?.invoke() + } - val decompiler = BaseDecompiler(bytecodeProvider, resultSaver, options, IdeaLogger()) - for (path in bytecodeMap.keys) { - decompiler.addSpace(path, true) + val decompiler = BaseDecompiler(bytecodeProvider, resultSaver, options, IdeaLogger()) + for (path in bytecodeMap.keys) { + decompiler.addSpace(path, true) + } + decompiler.decompileContext() + return resultSaver.resultText + } + catch (ex: IdeaLogger.InternalException) { + throw DecompileFailedException(ex.message ?: "Unknown error", ex) } - decompiler.decompileContext() - return resultSaver.resultText } private fun bytecodeMapForExistingClassfile(file: VirtualFile): Map ByteArray> { diff --git a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java index 0a66ac7e492..c4a1f391590 100644 --- a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java +++ b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java @@ -34,7 +34,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindow; import com.intellij.util.Alarm; import org.jetbrains.annotations.NotNull; -import org.jetbrains.java.decompiler.IdeaLogger; import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory; @@ -213,7 +212,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable { try { KotlinDecompilerAdapterKt.showDecompiledCode(file); } - catch (IdeaLogger.InternalException ex) { + catch (DecompileFailedException ex) { LOG.info(ex); Messages.showErrorDialog(myProject, "Failed to decompile " + file.getName() + ": " + ex, "Kotlin Bytecode Decompiler"); } diff --git a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerService.kt b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerService.kt index d4d1b4a324c..758c54ddbae 100644 --- a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerService.kt +++ b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerService.kt @@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.internal import com.intellij.openapi.components.ServiceManager import org.jetbrains.kotlin.psi.KtFile +class DecompileFailedException(message: String, cause: Throwable) : RuntimeException(message, cause) + interface KotlinDecompilerService { fun decompile(file: KtFile): String?