Skip to content

Commit a0958a8

Browse files
committed
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
Reviewed-by: sgehwolf Backport-of: dafc483
1 parent 66d4ee9 commit a0958a8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public void hardmsg(String key, Object... args) {
864864
*/
865865
@Override
866866
public void errormsg(String key, Object... args) {
867-
error(messageFormat(key, args));
867+
error("%s", messageFormat(key, args));
868868
}
869869

870870
/**

test/langtools/jdk/jshell/ToolSimpleTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @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 8239536
26+
* @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 8239536 8210959
2727
* @summary Simple jshell tool tests
2828
* @modules jdk.compiler/com.sun.tools.javac.api
2929
* jdk.compiler/com.sun.tools.javac.main
@@ -32,8 +32,9 @@
3232
* @build KullaTesting TestingInputStream
3333
* @run testng/othervm ToolSimpleTest
3434
*/
35-
import java.util.Arrays;
35+
3636
import java.util.ArrayList;
37+
import java.util.Arrays;
3738
import java.util.List;
3839
import java.util.Locale;
3940
import java.util.function.Consumer;
@@ -112,6 +113,20 @@ public void testChainedThrow() {
112113
);
113114
}
114115

116+
@Test
117+
public void testThrowWithPercent() {
118+
test(
119+
(a) -> assertCommandCheckOutput(a,
120+
"URI u = new URI(\"http\", null, \"h\", -1, \"a\" + (char)0x04, null, null);", (s) ->
121+
assertTrue(s.contains("URISyntaxException") && !s.contains("JShellTool"),
122+
"Output: '" + s + "'")),
123+
(a) -> assertCommandCheckOutput(a,
124+
"throw new Exception(\"%z\")", (s) ->
125+
assertTrue(s.contains("java.lang.Exception") && !s.contains("UnknownFormatConversionException"),
126+
"Output: '" + s + "'"))
127+
);
128+
}
129+
115130
@Test
116131
public void oneLineOfError() {
117132
test(

0 commit comments

Comments
 (0)