Repl: fix a problem where handling an incomplete message led to xml parsing exception
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user