src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
changeset 50017 88cc95780b6e
parent 49856 5f63af8f9d7f
child 50043 2d1952d4d067
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri May 04 16:49:22 2018 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri May 04 23:19:10 2018 -0700
@@ -40,6 +40,9 @@
 import java.lang.module.ModuleDescriptor;
 import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleReference;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
@@ -2999,13 +3002,22 @@
                 } else {
                     Path path = toPathResolvingUserHome(filename);
                     String resource;
-                    scanner = new Scanner(
-                            (!Files.exists(path) && (resource = getResource(filename)) != null)
-                            ? new StringReader(resource) // Not found as file, but found as resource
-                            : new FileReader(path.toString())
-                    );
+                    if (Files.exists(path)) {
+                        scanner = new Scanner(new FileReader(path.toString()));
+                    } else if ((resource = getResource(filename)) != null) {
+                        scanner = new Scanner(new StringReader(resource));
+                    } else {
+                        try {
+                            var url = new URL(filename);
+                            scanner = new Scanner(url.openStream());
+                        } catch (MalformedURLException mue) {
+                            throw new FileNotFoundException(filename);
+                        }
+                    }
                 }
-                run(new ScannerIOContext(scanner));
+                try (var scannerIOContext = new ScannerIOContext(scanner)) {
+                    run(scannerIOContext);
+                }
                 return true;
             } catch (FileNotFoundException e) {
                 errormsg("jshell.err.file.not.found", context, filename, e.getMessage());