8133507: JShell: StackTraceElement#getFileName of EvalException does not use custom id generator
Reviewed-by: jlahoda
This commit is contained in:
parent
161e3c650a
commit
7a3d0498d3
langtools
@ -555,9 +555,11 @@ class Eval {
|
||||
: "";
|
||||
} 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 @@ class Eval {
|
||||
}
|
||||
}
|
||||
|
||||
private EvalException translateExecutionException(UserException ex) {
|
||||
private StackTraceElement[] translateExceptionStack(Exception ex) {
|
||||
StackTraceElement[] raw = ex.getStackTrace();
|
||||
int last = raw.length;
|
||||
do {
|
||||
@ -759,11 +761,14 @@ class Eval {
|
||||
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) {
|
||||
|
@ -99,19 +99,18 @@ public class IdGeneratorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user