8175304: JShell tool: The /reset command hangs after setting a startup script
Reviewed-by: jlahoda
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Mar 06 08:36:05 2017 -0800
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Mar 06 08:57:41 2017 -0800
@@ -195,6 +195,7 @@
private boolean debug = false;
public boolean testPrompt = false;
private Startup startup = null;
+ private boolean isCurrentlyRunningStartup = false;
private String executionControlSpec = null;
private EditorSetting editor = BUILT_IN_EDITOR;
@@ -1019,7 +1020,19 @@
analysis = state.sourceCodeAnalysis();
live = true;
- startUpRun(startup.toString());
+ // Run the start-up script.
+ // Avoid an infinite loop running start-up while running start-up.
+ // This could, otherwise, occur when /env /reset or /reload commands are
+ // in the start-up script.
+ if (!isCurrentlyRunningStartup) {
+ try {
+ isCurrentlyRunningStartup = true;
+ startUpRun(startup.toString());
+ } finally {
+ isCurrentlyRunningStartup = false;
+ }
+ }
+ // Record subsequent snippets in the main namespace.
currentNameSpace = mainNamespace;
}
--- a/langtools/test/jdk/jshell/ToolBasicTest.java Mon Mar 06 08:36:05 2017 -0800
+++ b/langtools/test/jdk/jshell/ToolBasicTest.java Mon Mar 06 08:57:41 2017 -0800
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304
* @summary Tests for Basic tests for REPL tool
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -273,6 +273,32 @@
);
}
+ public void testEnvInStartUp() {
+ Compiler compiler = new Compiler();
+ Path outDir = Paths.get("testClasspathDirectory");
+ compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }");
+ Path classpath = compiler.getPath(outDir);
+ Path sup = compiler.getPath("startup.jsh");
+ compiler.writeToFile(sup,
+ "int xxx;\n" +
+ "/env -class-path " + classpath + "\n" +
+ "int aaa = 735;\n"
+ );
+ test(
+ (a) -> assertCommand(a, "/set start -retain " + sup, ""),
+ (a) -> assertCommand(a, "/reset",
+ "| Resetting state."),
+ (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"),
+ (a) -> assertCommand(a, "aaa", "aaa ==> 735")
+ );
+ test(
+ (a) -> assertCommandOutputContains(a, "/env", "--class-path"),
+ (a) -> assertCommandOutputContains(a, "xxx", "cannot find symbol", "variable xxx"),
+ (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"),
+ (a) -> assertCommand(a, "aaa", "aaa ==> 735")
+ );
+ }
+
private String makeSimpleJar() {
Compiler compiler = new Compiler();
Path outDir = Paths.get("testClasspathJar");