8133507: JShell: StackTraceElement#getFileName of EvalException does not use custom id generator
Reviewed-by: jlahoda
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Mon Aug 29 15:53:03 2016 +0200
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Thu Sep 01 12:13:13 2016 -0700
@@ -555,9 +555,11 @@
: "";
} catch (ResolutionException ex) {
DeclarationSnippet sn = (DeclarationSnippet) state.maps.getSnippetDeadOrAlive(ex.id());
- exception = new UnresolvedReferenceException(sn, ex.getStackTrace());
+ exception = new UnresolvedReferenceException(sn, translateExceptionStack(ex));
} catch (UserException ex) {
- exception = translateExecutionException(ex);
+ exception = new EvalException(translateExceptionMessage(ex),
+ ex.causeExceptionClass(),
+ translateExceptionStack(ex));
} catch (RunException ex) {
// StopException - no-op
} catch (InternalException ex) {
@@ -732,7 +734,7 @@
}
}
- private EvalException translateExecutionException(UserException ex) {
+ private StackTraceElement[] translateExceptionStack(Exception ex) {
StackTraceElement[] raw = ex.getStackTrace();
int last = raw.length;
do {
@@ -759,11 +761,14 @@
elems[i] = r;
}
}
+ return elems;
+ }
+
+ private String translateExceptionMessage(Exception ex) {
String msg = ex.getMessage();
- if (msg.equals("<none>")) {
- msg = null;
- }
- return new EvalException(msg, ex.causeExceptionClass(), elems);
+ return msg.equals("<none>")
+ ? null
+ : msg;
}
private boolean isWrap(StackTraceElement ste) {
--- a/langtools/test/jdk/jshell/IdGeneratorTest.java Mon Aug 29 15:53:03 2016 +0200
+++ b/langtools/test/jdk/jshell/IdGeneratorTest.java Thu Sep 01 12:13:13 2016 -0700
@@ -99,19 +99,18 @@
}
}
- @Test(enabled = false) // TODO 8133507
public void testIdInException() {
JShell.Builder builder = getBuilder().idGenerator(((snippet, id) -> "custom" + id));
try (JShell jShell = builder.build()) {
EvalException evalException = (EvalException) jShell.eval("throw new Error();").get(0).exception();
for (StackTraceElement ste : evalException.getStackTrace()) {
- assertTrue(ste.getFileName().startsWith("custom"), "Not started with \"custom\": "
+ assertTrue(ste.getFileName().startsWith("#custom"), "Not started with \"#custom\": "
+ ste.getFileName());
}
jShell.eval("void f() { g(); }");
UnresolvedReferenceException unresolvedException = (UnresolvedReferenceException) jShell.eval("f();").get(0).exception();
for (StackTraceElement ste : unresolvedException.getStackTrace()) {
- assertTrue(ste.getFileName().startsWith("custom"), "Not started with \"custom\": "
+ assertTrue(ste.getFileName().startsWith("#custom"), "Not started with \"#custom\": "
+ ste.getFileName());
}
}