Skip to content
Permalink
Browse files
8210959: JShell fails and exits when statement throws an exception wh…
…ose message contains a '%'.

Reviewed-by: sgehwolf
Backport-of: dafc483
  • Loading branch information
shipilev committed Jun 25, 2021
1 parent 66d4ee9 commit a0958a85f1f78158e2fd67770129483c5df18f5b
Showing with 18 additions and 3 deletions.
  1. +1 −1 src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
  2. +17 −2 test/langtools/jdk/jshell/ToolSimpleTest.java
@@ -864,7 +864,7 @@ public void hardmsg(String key, Object... args) {
*/
@Override
public void errormsg(String key, Object... args) {
error(messageFormat(key, args));
error("%s", messageFormat(key, args));
}

/**
@@ -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 8239536
* @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
* @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/othervm ToolSimpleTest
*/
import java.util.Arrays;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
@@ -112,6 +113,20 @@ public void testChainedThrow() {
);
}

@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(

1 comment on commit a0958a8

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on a0958a8 Jun 25, 2021

Please sign in to comment.