Skip to content

Commit 3b9696a

Browse files
author
mgricken
committed
Bugfix for 3008828: throw null
http://sourceforge.net/tracker/index.php?func=detail&aid=3008828&group_id=44253&atid=438935 Fixed in DynamicJava: As per Java Language Specification (JLS): http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.18 "If evaluation of the Expression completes normally, producing a null value, then an instance V of class NullPointerException is created and thrown instead of null." M dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/StatementEvaluator.java M drjava/lib/dynamicjava-base.jar M drjava/src/edu/rice/cs/drjava/model/repl/JavaInterpreterTest.java git-svn-id: file:///tmp/test-svn/trunk@5261 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 01be6f1 commit 3b9696a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

drjava/lib/dynamicjava-base.jar

-667 Bytes
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/repl/JavaInterpreterTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,24 @@ public void testUserDefinedVoidMethod() throws InterpreterException {
555555
Object result = interpret("public void foo() {}; foo()");
556556
assertSame("Should have returned NO_RESULT.", null, result);
557557
}
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+
558578
}

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/StatementEvaluator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ public Object next() {
305305

306306
@Override public Result visit(ThrowStatement node) {
307307
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+
}
308317
throw new WrappedException(new EvaluatorException(t));
309318
}
310319

0 commit comments

Comments
 (0)