From 5320a32d67465fd0dfcdcfa3b0249cfab3d7259f Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Thu, 3 Feb 2022 13:24:53 +0100 Subject: [PATCH] Check also the cause of throwable for OOM exception Sometimes OOM exception is the cause of some higher-level one exception in compilation. ^KT-51116 Fixed --- .../cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt index 365c77a53ee..0980e6bffee 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt @@ -121,12 +121,17 @@ abstract class CLICompiler : CLITool() { return COMPILATION_ERROR } catch (t: Throwable) { MessageCollectorUtil.reportException(collector, t) - return if (t is OutOfMemoryError) OOM_ERROR else INTERNAL_ERROR + return if (t is OutOfMemoryError || t.hasOOMCause()) OOM_ERROR else INTERNAL_ERROR } finally { collector.flush() } } + private fun Throwable.hasOOMCause(): Boolean = when (cause) { + is OutOfMemoryError -> true + else -> cause?.hasOOMCause() ?: false + } + private fun MessageCollector.reportCompilationCancelled(e: CompilationCanceledException) { if (e !is IncrementalNextRoundException) { report(INFO, "Compilation was canceled", null)