| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 01be6f1 commit 3b9696a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,4 +555,24 @@ public void testUserDefinedVoidMethod() throws InterpreterException { | |||
| 555 | 555 | Object result = interpret("public void foo() {}; foo()"); | |
| 556 | 556 | assertSame("Should have returned NO_RESULT.", null, result); | |
| 557 | 557 | } | |
| 558 | + | ||
| 559 | + /** Test throwing null, for bug 3008828. */ | ||
| 560 | + public void testThrowNull() throws InterpreterException { | ||
| 561 | + try { | ||
| 562 | + _interpreter.interpret("throw null"); | ||
| 563 | + fail("Should have thrown an EvaluatorException with a NullPointerException as cause."); | ||
| 564 | + } | ||
| 565 | + catch(Throwable t) { | ||
| 566 | + if ((t == null) || (!(t instanceof EvaluatorException))) { | ||
| 567 | + fail("Should have thrown an EvaluatorException with a NullPointerException as cause."); | ||
| 568 | + } | ||
| 569 | + else { | ||
| 570 | + Throwable cause = t.getCause(); | ||
| 571 | + if (!(cause instanceof NullPointerException)) { | ||
| 572 | + fail("Should have thrown an EvaluatorException with a NullPointerException as cause."); | ||
| 573 | + } | ||
| 574 | + } | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + | ||
| 558 | 578 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -305,6 +305,15 @@ public Object next() { | |||
| 305 | 305 | ||
| 306 | 306 | @Override public Result visit(ThrowStatement node) { | |
| 307 | 307 | Throwable t = (Throwable) new ExpressionEvaluator(_bindings, _opt).value(node.getExpression()); | |
| 308 | + // bug fix for DrJava bug 3008828 | ||
| 309 | + if (t == null) { | ||
| 310 | + // as per Java Language Specification (JLS): | ||
| 311 | + // http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.18 | ||
| 312 | + // "If evaluation of the Expression completes normally, producing a null value, | ||
| 313 | + // then an instance VÕ of class NullPointerException is created and thrown instead of null." | ||
| 314 | + t = new NullPointerException(); | ||
| 315 | + t.setStackTrace(new StackTraceElement[0]); | ||
| 316 | + } | ||
| 308 | 317 | throw new WrappedException(new EvaluatorException(t)); | |
| 309 | 318 | } | |
| 310 | 319 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments