Repl: fix a problem where handling an incomplete message led to xml parsing exception

This commit is contained in:
Pavel V. Talanov
2015-10-26 13:38:04 +03:00
parent e20bcbde53
commit 6237e516d4
2 changed files with 20 additions and 1 deletions
@@ -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")
@@ -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")
}
}