diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java index 5d95bc7c77d3f..1317a036982a7 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java @@ -1312,6 +1312,9 @@ private String getInput(String initial) throws IOException{ continue; } if (line == null) { + if (!src.isEmpty()) { + errormsg("jshell.err.incomplete.input", src); + } //EOF if (input.interactiveOutput()) { // End after user ctrl-D diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties index 44ad74611e5b7..351a0f812ad03 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties @@ -169,6 +169,7 @@ jshell.err.exception.thrown = Exception {0} jshell.err.exception.thrown.message = Exception {0}: {1} jshell.err.exception.cause = Caused by: {0} jshell.err.exception.cause.message = Caused by: {0}: {1} +jshell.err.incomplete.input = Incomplete input: {0} jshell.console.see.synopsis = jshell.console.see.full.documentation = diff --git a/test/langtools/jdk/jshell/StartOptionTest.java b/test/langtools/jdk/jshell/StartOptionTest.java index b84b454480e5e..140aab6a14c26 100644 --- a/test/langtools/jdk/jshell/StartOptionTest.java +++ b/test/langtools/jdk/jshell/StartOptionTest.java @@ -22,12 +22,13 @@ */ /* - * @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383 8341631 + * @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383 8341631 8341833 * @summary Testing startExCe-up options. * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * jdk.jdeps/com.sun.tools.javap * jdk.jshell/jdk.internal.jshell.tool + * jdk.jshell/jdk.internal.jshell.tool.resources:+open * @library /tools/lib * @build Compiler toolbox.ToolBox * @run testng StartOptionTest @@ -38,13 +39,16 @@ import java.io.PrintStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.text.MessageFormat; import java.util.HashMap; import java.util.Locale; +import java.util.ResourceBundle; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; +import jdk.jshell.JShell; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -133,6 +137,14 @@ protected void startCheckUserOutput(Consumer checkUserOutput, check(usererr, null, "usererr"); } + protected void startCheckError(Consumer checkError, + String... args) { + runShell(args); + check(cmderr, checkError, "userout"); + check(userout, null, "userout"); + check(usererr, null, "usererr"); + } + // Start with an exit code and command error check protected void startExCe(int eec, Consumer checkError, String... args) { StartOptionTest.this.startExCoUoCeCn( @@ -411,6 +423,25 @@ public void testInput() { readPasswordPrompt); } + public void testErroneousFile() { + String code = """ + var v = ( + System.console().readLine("prompt: "); + /exit + """; + String readLinePrompt = writeToFile(code); + String expectedErrorFormat = + ResourceBundle.getBundle("jdk.internal.jshell.tool.resources.l10n", + Locale.getDefault(), + JShell.class.getModule()) + .getString("jshell.err.incomplete.input"); + String expectedError = + new MessageFormat(expectedErrorFormat).format(new Object[] {code}); + startCheckError(s -> assertEquals(s, expectedError), + readLinePrompt); + } + + @AfterMethod public void tearDown() { cmdout = null;