# HG changeset patch # User rfield # Date 1472757193 25200 # Node ID e57f1a5c9346608e4f051ebd8625ac823eba6841 # Parent 8b6a878d87735199dec498b922a5ca9169261a57 8133507: JShell: StackTraceElement#getFileName of EvalException does not use custom id generator Reviewed-by: jlahoda diff -r 8b6a878d8773 -r e57f1a5c9346 langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java --- 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("")) { - msg = null; - } - return new EvalException(msg, ex.causeExceptionClass(), elems); + return msg.equals("") + ? null + : msg; } private boolean isWrap(StackTraceElement ste) { diff -r 8b6a878d8773 -r e57f1a5c9346 langtools/test/jdk/jshell/IdGeneratorTest.java --- 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()); } }