8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
Reviewed-by: jlahoda
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Oct 22 08:30:39 2018 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Oct 22 09:26:50 2018 -0700
@@ -864,7 +864,7 @@
*/
@Override
public void errormsg(String key, Object... args) {
- error(messageFormat(key, args));
+ error("%s", messageFormat(key, args));
}
/**
--- a/test/langtools/jdk/jshell/ToolSimpleTest.java Mon Oct 22 08:30:39 2018 -0700
+++ b/test/langtools/jdk/jshell/ToolSimpleTest.java Mon Oct 22 09:26:50 2018 -0700
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596
+ * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959
* @summary Simple jshell tool tests
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -32,8 +32,9 @@
* @build KullaTesting TestingInputStream
* @run testng ToolSimpleTest
*/
+
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
@@ -158,6 +159,20 @@
}
@Test
+ public void testThrowWithPercent() {
+ test(
+ (a) -> assertCommandCheckOutput(a,
+ "URI u = new URI(\"http\", null, \"h\", -1, \"a\" + (char)0x04, null, null);", (s) ->
+ assertTrue(s.contains("URISyntaxException") && !s.contains("JShellTool"),
+ "Output: '" + s + "'")),
+ (a) -> assertCommandCheckOutput(a,
+ "throw new Exception(\"%z\")", (s) ->
+ assertTrue(s.contains("java.lang.Exception") && !s.contains("UnknownFormatConversionException"),
+ "Output: '" + s + "'"))
+ );
+ }
+
+ @Test
public void oneLineOfError() {
test(
(a) -> assertCommand(a, "12+", null),