8299829: In jshell, the output of "0".repeat(49999)+"2" ends with a '0'

Reviewed-by: jlahoda
This commit is contained in:
Adam Sotona 2023-01-11 08:30:48 +00:00
parent ef32fdb8cc
commit 030e88d638
2 changed files with 8 additions and 3 deletions

View File

@ -57,6 +57,10 @@ class ExecutionControlForwarder {
*/
private static final int MAX_UTF_CHARS = 21844;
private static final int TRUNCATE_END = MAX_UTF_CHARS / 3;
private static final String TRUNCATE_JOIN = " ... ";
private static final int TRUNCATE_START = MAX_UTF_CHARS - TRUNCATE_JOIN.length() - TRUNCATE_END;
private final ExecutionControl ec;
private final ObjectInput in;
private final ObjectOutput out;
@ -108,7 +112,7 @@ class ExecutionControlForwarder {
s = "";
} else if (s.length() > MAX_UTF_CHARS) {
// Truncate extremely long strings to prevent writeUTF from crashing the VM
s = s.substring(0, MAX_UTF_CHARS);
s = s.substring(0, TRUNCATE_START) + TRUNCATE_JOIN + s.substring(s.length() - TRUNCATE_END);
}
out.writeUTF(s);
}

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8148316 8148317 8151755 8152246 8153551 8154812 8157261 8163840 8166637 8161969 8173007
* @bug 8148316 8148317 8151755 8152246 8153551 8154812 8157261 8163840 8166637 8161969 8173007 8299829
* @summary Tests for output customization
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -300,7 +300,8 @@ public class ToolFormatTest extends ReplToolTesting {
(a) -> assertCommand(a, "/var", "| String s = \"ABACABADA"),
(a) -> assertCommand(a, "String r = s", "String:\"ABACABAD ... BAXYZ\""),
(a) -> assertCommand(a, "r", "String:\"ABACABADA"),
(a) -> assertCommand(a, "r=s", "String:\"AB")
(a) -> assertCommand(a, "r=s", "String:\"AB"),
(a) -> assertCommand(a, "\"0\".repeat(49999)+\"2\"", "String:\"00000000 ... 00002\"")
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {