8210527: JShell: NullPointerException in jdk.jshell.Eval.translateExceptionStack
8232855: jshell missing word in /help help Reviewed-by: jlahoda
This commit is contained in:
parent
dd321330ce
commit
dca6e34397
@ -488,9 +488,9 @@ Display information about using the jshell tool.\n\
|
|||||||
/help\n\t\
|
/help\n\t\
|
||||||
List the jshell tool commands and help subjects\n\n\
|
List the jshell tool commands and help subjects\n\n\
|
||||||
/help <command>\n\t\
|
/help <command>\n\t\
|
||||||
Display information about the specified command. The slash must be included.\n\t\
|
Display information about the specified command.\n\t\
|
||||||
Only the first few letters of the command are needed -- if more than one\n\t\
|
Only the first few letters of the command are needed -- if there is more than\n\t\
|
||||||
each will be displayed. Example: /help /li\n\n\
|
one match, each will be displayed. Example: /help /li\n\n\
|
||||||
/help <subject>\n\t\
|
/help <subject>\n\t\
|
||||||
Display information about the specified help subject. Example: /help intro
|
Display information about the specified help subject. Example: /help intro
|
||||||
|
|
||||||
@ -529,9 +529,9 @@ Display information about using the jshell tool (abbreviation for /help).\n\
|
|||||||
/?\n\t\
|
/?\n\t\
|
||||||
Display list of commands and help subjects\n\
|
Display list of commands and help subjects\n\
|
||||||
/? <command>\n\t\
|
/? <command>\n\t\
|
||||||
Display information about the specified command. The slash must be included.\n\t\
|
Display information about the specified command.\n\t\
|
||||||
Only the first few letters of the command are needed -- if more than one\n\t\
|
Only the first few letters of the command are needed -- if there is more than\n\t\
|
||||||
match, each will be displayed. Example: /? /li\n\
|
one match, each will be displayed. Example: /? /li\n\n\
|
||||||
/? <subject>\n\t\
|
/? <subject>\n\t\
|
||||||
Display information about the specified help subject. Example: /? intro
|
Display information about the specified help subject. Example: /? intro
|
||||||
|
|
||||||
|
@ -1110,7 +1110,7 @@ class Eval {
|
|||||||
Snippet sn = outer.wrapLineToSnippet(wln);
|
Snippet sn = outer.wrapLineToSnippet(wln);
|
||||||
String file = "#" + sn.id();
|
String file = "#" + sn.id();
|
||||||
elems[i] = new StackTraceElement(klass, method, file, line);
|
elems[i] = new StackTraceElement(klass, method, file, line);
|
||||||
} else if (r.getFileName().equals("<none>")) {
|
} else if ("<none>".equals(r.getFileName())) {
|
||||||
elems[i] = new StackTraceElement(r.getClassName(), r.getMethodName(), null, r.getLineNumber());
|
elems[i] = new StackTraceElement(r.getClassName(), r.getMethodName(), null, r.getLineNumber());
|
||||||
} else {
|
} else {
|
||||||
elems[i] = r;
|
elems[i] = r;
|
||||||
|
@ -24,8 +24,13 @@
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Tests for exceptions
|
* @summary Tests for exceptions
|
||||||
* @bug 8198801 8212167
|
* @bug 8198801 8212167 8210527
|
||||||
* @build KullaTesting TestingInputStream
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
|
* jdk.compiler/com.sun.tools.javac.main
|
||||||
|
* jdk.jdeps/com.sun.tools.javap
|
||||||
|
* @library /tools/lib
|
||||||
|
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
|
||||||
|
* @build KullaTesting TestingInputStream Compiler
|
||||||
* @run testng ExceptionsTest
|
* @run testng ExceptionsTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -38,6 +43,9 @@ import jdk.jshell.Snippet;
|
|||||||
import jdk.jshell.SnippetEvent;
|
import jdk.jshell.SnippetEvent;
|
||||||
import jdk.jshell.UnresolvedReferenceException;
|
import jdk.jshell.UnresolvedReferenceException;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.*;
|
||||||
@ -45,6 +53,9 @@ import static org.testng.Assert.*;
|
|||||||
@Test
|
@Test
|
||||||
public class ExceptionsTest extends KullaTesting {
|
public class ExceptionsTest extends KullaTesting {
|
||||||
|
|
||||||
|
private final Compiler compiler = new Compiler();
|
||||||
|
private final Path outDir = Paths.get("test_class_path");
|
||||||
|
|
||||||
public void throwUncheckedException() {
|
public void throwUncheckedException() {
|
||||||
String message = "error_message";
|
String message = "error_message";
|
||||||
SnippetEvent cr = assertEvalException("throw new RuntimeException(\"" + message + "\");");
|
SnippetEvent cr = assertEvalException("throw new RuntimeException(\"" + message + "\");");
|
||||||
@ -207,6 +218,36 @@ public class ExceptionsTest extends KullaTesting {
|
|||||||
newStackTraceElement("", "", cr2.snippet(), 1)));
|
newStackTraceElement("", "", cr2.snippet(), 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test 8210527
|
||||||
|
public void throwFromWithoutSource() {
|
||||||
|
String message = "show this";
|
||||||
|
SnippetEvent se = assertEvalException("java.lang.reflect.Proxy.newProxyInstance(" +
|
||||||
|
"Thread.currentThread().getContextClassLoader(), new Class[] {}," +
|
||||||
|
"(p, m, a) -> { throw new IllegalStateException(\"" + message + "\"); }).hashCode()");
|
||||||
|
assertExceptionMatch(se,
|
||||||
|
new ExceptionInfo(IllegalStateException.class, message,
|
||||||
|
newStackTraceElement("", "lambda$do_it$$0", se.snippet(), 1),
|
||||||
|
new StackTraceElement("com.sun.proxy.$Proxy0", "hashCode", null, -1),
|
||||||
|
newStackTraceElement("", "", se.snippet(), 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// test 8210527
|
||||||
|
public void throwFromNoSource() {
|
||||||
|
Path path = outDir.resolve("fail");
|
||||||
|
compiler.compile(path,
|
||||||
|
"package fail;\n" +
|
||||||
|
"public class Fail {\n" +
|
||||||
|
" static { int x = 1 / 0; }\n" +
|
||||||
|
"}\n");
|
||||||
|
addToClasspath(compiler.getPath(path));
|
||||||
|
SnippetEvent se = assertEvalException("Class.forName(\"fail.Fail\")");
|
||||||
|
assertExceptionMatch(se,
|
||||||
|
new ExceptionInfo(ExceptionInInitializerError.class, null,
|
||||||
|
new StackTraceElement("java.lang.Class", "forName0", "Class.java", -2),
|
||||||
|
new StackTraceElement("java.lang.Class", "forName", "Class.java", -2),
|
||||||
|
newStackTraceElement("", "", se.snippet(), 1)));
|
||||||
|
}
|
||||||
|
|
||||||
// test 8212167
|
// test 8212167
|
||||||
public void throwLineFormat1() {
|
public void throwLineFormat1() {
|
||||||
SnippetEvent se = assertEvalException(
|
SnippetEvent se = assertEvalException(
|
||||||
@ -367,21 +408,23 @@ public class ExceptionsTest extends KullaTesting {
|
|||||||
for (int i = 0; i < actual.length; ++i) {
|
for (int i = 0; i < actual.length; ++i) {
|
||||||
StackTraceElement actualElement = actual[i];
|
StackTraceElement actualElement = actual[i];
|
||||||
StackTraceElement expectedElement = expected[i];
|
StackTraceElement expectedElement = expected[i];
|
||||||
assertEquals(actualElement.getClassName(), expectedElement.getClassName(), message + " : class names");
|
assertEquals(actualElement.getClassName(), expectedElement.getClassName(), message + " : class names [" + i + "]");
|
||||||
String expectedMethodName = expectedElement.getMethodName();
|
String expectedMethodName = expectedElement.getMethodName();
|
||||||
if (expectedMethodName.startsWith("lambda$")) {
|
if (expectedMethodName.startsWith("lambda$")) {
|
||||||
assertTrue(actualElement.getMethodName().startsWith("lambda$"), message + " : method names");
|
assertTrue(actualElement.getMethodName().startsWith("lambda$"), message + " : method names");
|
||||||
} else {
|
} else {
|
||||||
assertEquals(actualElement.getMethodName(), expectedElement.getMethodName(), message + " : method names");
|
assertEquals(actualElement.getMethodName(), expectedElement.getMethodName(), message + " : method names [" + i + "]");
|
||||||
}
|
}
|
||||||
assertEquals(actualElement.getFileName(), expectedElement.getFileName(), message + " : file names");
|
assertEquals(actualElement.getFileName(), expectedElement.getFileName(), message + " : file names [" + i + "]");
|
||||||
assertEquals(actualElement.getLineNumber(), expectedElement.getLineNumber(), message + " : line numbers"
|
if (expectedElement.getLineNumber() >= 0) {
|
||||||
|
assertEquals(actualElement.getLineNumber(), expectedElement.getLineNumber(), message + " : line numbers [" + i + "]"
|
||||||
+ " -- actual: " + actualElement.getLineNumber() + ", expected: " + expectedElement.getLineNumber() +
|
+ " -- actual: " + actualElement.getLineNumber() + ", expected: " + expectedElement.getLineNumber() +
|
||||||
" -- in: " + actualElement.getClassName());
|
" -- in: " + actualElement.getClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getStackTrace(Throwable ex) {
|
private String getStackTrace(Throwable ex) {
|
||||||
StringWriter st = new StringWriter();
|
StringWriter st = new StringWriter();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user