From 030e88d63844f185b839977ff1b19bbc4fe688e8 Mon Sep 17 00:00:00 2001 From: Adam Sotona Date: Wed, 11 Jan 2023 08:30:48 +0000 Subject: [PATCH] 8299829: In jshell, the output of "0".repeat(49999)+"2" ends with a '0' Reviewed-by: jlahoda --- .../jdk/jshell/execution/ExecutionControlForwarder.java | 6 +++++- test/langtools/jdk/jshell/ToolFormatTest.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java b/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java index 061e548878b..fdb126f93ec 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java @@ -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); } diff --git a/test/langtools/jdk/jshell/ToolFormatTest.java b/test/langtools/jdk/jshell/ToolFormatTest.java index 84ed32e91bd..3aaf5e79ea5 100644 --- a/test/langtools/jdk/jshell/ToolFormatTest.java +++ b/test/langtools/jdk/jshell/ToolFormatTest.java @@ -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 -> {