8196133: JShell crashes when attempting to use bad source file in class path
Reviewed-by: jlahoda
This commit is contained in:
parent
42dc61aad0
commit
4aa85f9489
@ -311,15 +311,18 @@ class TaskFactory {
|
||||
return fm.createSourceFileObject(w, w.classFullName(), w.wrapped());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source information from the wrap. If this is external, or
|
||||
* otherwise does not have wrap info, just use source code.
|
||||
* @param d the Diagnostic from the compiler
|
||||
* @return the corresponding Diag
|
||||
*/
|
||||
@Override
|
||||
public Diag diag(Diagnostic<? extends JavaFileObject> d) {
|
||||
SourceMemoryJavaFileObject smjfo = (SourceMemoryJavaFileObject) d.getSource();
|
||||
if (smjfo == null) {
|
||||
// Handle failure that doesn't preserve mapping
|
||||
return new StringSourceHandler().diag(d);
|
||||
}
|
||||
OuterWrap w = (OuterWrap) smjfo.getOrigin();
|
||||
return w.wrapDiag(d);
|
||||
JavaFileObject jfo = d.getSource();
|
||||
return jfo instanceof SourceMemoryJavaFileObject
|
||||
? ((OuterWrap) ((SourceMemoryJavaFileObject) jfo).getOrigin()).wrapDiag(d)
|
||||
: new StringSourceHandler().diag(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
* @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 8196133
|
||||
* @summary Tests for Basic tests for REPL tool
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -350,6 +350,34 @@ public class ToolBasicTest extends ReplToolTesting {
|
||||
);
|
||||
}
|
||||
|
||||
private String makeBadSourceJar() {
|
||||
Compiler compiler = new Compiler();
|
||||
Path outDir = Paths.get("testClasspathJar");
|
||||
Path src = compiler.getPath(outDir.resolve("pkg/A.java"));
|
||||
compiler.writeToFile(src, "package pkg; /** \u0086 */public class A { public String toString() { return \"A\"; } }");
|
||||
String jarName = "test.jar";
|
||||
compiler.jar(outDir, jarName, "pkg/A.java");
|
||||
return compiler.getPath(outDir).resolve(jarName).toString();
|
||||
}
|
||||
|
||||
public void testBadSourceJarClasspath() {
|
||||
String jarPath = makeBadSourceJar();
|
||||
test(
|
||||
(a) -> assertCommand(a, "/env --class-path " + jarPath,
|
||||
"| Setting new options and restoring state."),
|
||||
(a) -> assertCommandOutputStartsWith(a, "new pkg.A();",
|
||||
"| Error:\n"
|
||||
+ "| cannot find symbol\n"
|
||||
+ "| symbol: class A")
|
||||
);
|
||||
test(new String[]{"--class-path", jarPath},
|
||||
(a) -> assertCommandOutputStartsWith(a, "new pkg.A();",
|
||||
"| Error:\n"
|
||||
+ "| cannot find symbol\n"
|
||||
+ "| symbol: class A")
|
||||
);
|
||||
}
|
||||
|
||||
public void testModulePath() {
|
||||
Compiler compiler = new Compiler();
|
||||
Path modsDir = Paths.get("mods");
|
||||
|
Loading…
x
Reference in New Issue
Block a user