8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
Fixing handling of invalid paths. Reviewed-by: rfield
This commit is contained in:
parent
7362d58294
commit
17b766fb1d
@ -43,6 +43,7 @@ import java.lang.module.ModuleReference;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.MessageFormat;
|
||||
@ -381,7 +382,7 @@ public class JShellTool implements MessageHandler {
|
||||
private Collection<String> validPaths(Collection<String> vals, String context, boolean isModulePath) {
|
||||
Stream<String> result = vals.stream()
|
||||
.map(s -> Arrays.stream(s.split(File.pathSeparator))
|
||||
.map(sp -> toPathResolvingUserHome(sp))
|
||||
.flatMap(sp -> toPathImpl(sp, context))
|
||||
.filter(p -> checkValidPathEntry(p, context, isModulePath))
|
||||
.map(p -> p.toString())
|
||||
.collect(Collectors.joining(File.pathSeparator)));
|
||||
@ -421,6 +422,16 @@ public class JShellTool implements MessageHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Stream<Path> toPathImpl(String path, String context) {
|
||||
try {
|
||||
return Stream.of(toPathResolvingUserHome(path));
|
||||
} catch (InvalidPathException ex) {
|
||||
msg("jshell.err.file.not.found", context, path);
|
||||
failed = true;
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
Options parse(OptionSet options) {
|
||||
addOptions(OptionKind.CLASS_PATH,
|
||||
validPaths(options.valuesOf(argClassPath), "--class-path", false));
|
||||
|
@ -216,7 +216,9 @@ public class ToolSimpleTest extends ReplToolTesting {
|
||||
public void testInvalidClassPath() {
|
||||
test(
|
||||
a -> assertCommand(a, "/env --class-path snurgefusal",
|
||||
"| File 'snurgefusal' for '--class-path' is not found.")
|
||||
"| File 'snurgefusal' for '--class-path' is not found."),
|
||||
a -> assertCommand(a, "/env --class-path ?",
|
||||
"| File '?' for '--class-path' is not found.")
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user