8202690: jdk/jshell/ToolBasicTest.java failed in testOpenFileOverHttp() and testOpenLocalFileUrl()

Reviewed-by: rfield, jlahoda
This commit is contained in:
Chris Yin 2018-05-08 09:51:42 +08:00
parent b62fee0519
commit 7166041796
2 changed files with 24 additions and 8 deletions

View File

@ -42,6 +42,7 @@ import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
@ -3000,19 +3001,34 @@ public class JShellTool implements MessageHandler {
regenerateOnDeath = false; regenerateOnDeath = false;
scanner = new Scanner(cmdin); scanner = new Scanner(cmdin);
} else { } else {
Path path = toPathResolvingUserHome(filename); Path path = null;
URL url = null;
String resource; String resource;
if (Files.exists(path)) { try {
path = toPathResolvingUserHome(filename);
} catch (InvalidPathException ipe) {
try {
url = new URL(filename);
if (url.getProtocol().equalsIgnoreCase("file")) {
path = Paths.get(url.toURI());
}
} catch (MalformedURLException | URISyntaxException e) {
throw new FileNotFoundException(filename);
}
}
if (path != null && Files.exists(path)) {
scanner = new Scanner(new FileReader(path.toString())); scanner = new Scanner(new FileReader(path.toString()));
} else if ((resource = getResource(filename)) != null) { } else if ((resource = getResource(filename)) != null) {
scanner = new Scanner(new StringReader(resource)); scanner = new Scanner(new StringReader(resource));
} else { } else {
try { if (url == null) {
var url = new URL(filename); try {
scanner = new Scanner(url.openStream()); url = new URL(filename);
} catch (MalformedURLException mue) { } catch (MalformedURLException mue) {
throw new FileNotFoundException(filename); throw new FileNotFoundException(filename);
}
} }
scanner = new Scanner(url.openStream());
} }
} }
try (var scannerIOContext = new ScannerIOContext(scanner)) { try (var scannerIOContext = new ScannerIOContext(scanner)) {

View File

@ -501,7 +501,7 @@ public class ToolBasicTest extends ReplToolTesting {
compiler.writeToFile(path, "int a = 10;int b = 20;int c = a + b;\n"); compiler.writeToFile(path, "int a = 10;int b = 20;int c = a + b;\n");
for (String s : new String[]{"/o", "/open"}) { for (String s : new String[]{"/o", "/open"}) {
test( test(
(a) -> assertCommand(a, s + " file://" + path.toString(), ""), (a) -> assertCommand(a, s + " " + path.toUri(), ""),
(a) -> assertCommand(a, "a", "a ==> 10"), (a) -> assertCommand(a, "a", "a ==> 10"),
(a) -> assertCommand(a, "b", "b ==> 20"), (a) -> assertCommand(a, "b", "b ==> 20"),
(a) -> assertCommand(a, "c", "c ==> 30") (a) -> assertCommand(a, "c", "c ==> 30")