Skip to content
Permalink
Browse files
8254196: jshell infinite loops when startup script contains System.ex…
…it call

Reviewed-by: sundar
  • Loading branch information
Jan Lahoda committed Mar 24, 2021
1 parent a79f095 commit 6c0fbf70e89fe55f43d0f11ba5120e4de4521e90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
@@ -1164,7 +1164,11 @@ private void initFeedback(String initMode) {
//where
private void startUpRun(String start) {
try (IOContext suin = new ScannerIOContext(new StringReader(start))) {
run(suin);
while (run(suin)) {
if (!live) {
resetState();
}
}
} catch (Exception ex) {
errormsg("jshell.err.startup.unexpected.exception", ex);
ex.printStackTrace(cmderr);
@@ -1186,8 +1190,10 @@ private void closeState() {
* Main loop
*
* @param in the line input/editing context
* @return true iff something remains in the input after this method finishes
* (e.g. due to live == false).
*/
private void run(IOContext in) {
private boolean run(IOContext in) {
IOContext oldInput = input;
input = in;
try {
@@ -1201,11 +1207,13 @@ private void run(IOContext in) {
}
} catch (EOFException ex) {
// Just exit loop
return false;
} catch (IOException ex) {
errormsg("jshell.err.unexpected.exception", ex);
} finally {
input = oldInput;
}
return true;
}

/**
@@ -24,6 +24,7 @@
*/
package jdk.jshell.execution;

import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -341,6 +342,8 @@ private void readAndReportExecutionResult() throws RunException,
throw new EngineTerminationException("Bad remote result code: " + status);
}
}
} catch (EOFException ex) {
throw new EngineTerminationException("Terminated.");
} catch (IOException | ClassNotFoundException ex) {
ex.printStackTrace();
throw new EngineTerminationException(ex.toString());
@@ -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 8175304 8167554 8180508 8166232 8196133 8199912 8211694 8223688
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133 8199912 8211694 8223688 8254196
* @summary Tests for Basic tests for REPL tool
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -48,6 +48,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.function.Consumer;
@@ -889,4 +890,16 @@ public void testIndent() { //8223688
);
}

public void testSystemExitStartUp() {
Compiler compiler = new Compiler();
Path startup = compiler.getPath("SystemExitStartUp/startup.txt");
compiler.writeToFile(startup, "int i1 = 0;\n" +
"System.exit(0);\n" +
"int i2 = 0;\n");
test(Locale.ROOT, true, new String[]{"--startup", startup.toString()},
"State engine terminated.",
(a) -> assertCommand(a, "i2", "i2 ==> 0"),
(a) -> assertCommandOutputContains(a, "i1", "Error:", "variable i1")
);
}
}

0 comments on commit 6c0fbf7

Please sign in to comment.