From 6237e516d422947d2a18a094ab4740765da2d3c0 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 26 Oct 2015 13:38:04 +0300 Subject: [PATCH] Repl: fix a problem where handling an incomplete message led to xml parsing exception --- .../jetbrains/kotlin/console/ReplOutputHandler.kt | 12 +++++++++++- .../jetbrains/kotlin/idea/console/KotlinReplTest.kt | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt index ea4125b2d54..c7f74be0ec3 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt @@ -44,6 +44,7 @@ class ReplOutputHandler( private var isBuildInfoChecked = false private val dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() private val outputProcessor = ReplOutputProcessor(runner) + private val inputBuffer = StringBuilder() override fun isSilentlyDestroyOnClose() = true @@ -52,8 +53,17 @@ class ReplOutputHandler( if (text.startsWith("warning: classpath entry points to a non-existent location")) return // skip "/usr/lib/jvm/java-8-oracle/bin/java -cp ..." intro - if (!text.startsWith(XML_PREFIX)) return super.notifyTextAvailable(text, key) + if (!text.startsWith(XML_PREFIX) && inputBuffer.length == 0) return super.notifyTextAvailable(text, key) + inputBuffer.append(text) + val resultingText = inputBuffer.toString() + if (resultingText.endsWith("\n")) { + handleReplMessage(resultingText) + inputBuffer.setLength(0) + } + } + + private fun handleReplMessage(text: String) { val output = dBuilder.parse(strToSource(text)) val root = output.firstChild as Element val outputType = root.getAttribute("type") diff --git a/idea/tests/org/jetbrains/kotlin/idea/console/KotlinReplTest.kt b/idea/tests/org/jetbrains/kotlin/idea/console/KotlinReplTest.kt index b5e95feddc0..7105a72e176 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/console/KotlinReplTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/console/KotlinReplTest.kt @@ -132,4 +132,13 @@ public class KotlinReplTest : PlatformTestCase() { sendCommand("println(\"$message\")") waitForExpectedOutput(message) } + + @Test fun testMultipleErrorsHandling() { + val veryLongTextWithErrors = "println($);".repeat(30) + sendCommand(veryLongTextWithErrors) + sendCommand(veryLongTextWithErrors) + sendCommand(veryLongTextWithErrors) + sendCommand("println(\"OK\")") + waitForExpectedOutput("OK") + } } \ No newline at end of file