The Philosophy of Nothing

Neal Gafter neal at gafter.com
Mon Nov 30 21:53:08 PST 2009


On Mon, Nov 30, 2009 at 9:08 PM, Paul Benedict <pbenedict at apache.org> wrote:

> Some questions about Nothing that the spec may want to address:
>
> 1) How can the compiler absolutely prove that "statements or expressions
> cannot complete normally"? I imagine that can only be done if a "throw" is
> literally found in the method body. Can't method calls prevent the
> inference?
>

The compiler has a conservative flow analysis that can prove that certain
code is definitely unreachable.  The specification for that is already in
JLS3, and referenced in the 0.6 spec, with the appropriate additions already
noted in 0.6.  Throwing an exception is the most common way for it to
happen, but with the introduction of Nothing calling a method that returns
Nothing is another way.

2) Outside of the whole closure conversation, can java.lang.Nothing be used?
> And is there value in it? For example:
> class Test {
>  public Nothing throw_it() {
>    throw new AssertionError();
>  }
> }
>

Yes, but the most important use cases arise with closures.

3) In regards to byte-code manipulation, what would happen at runtime if a
> class transformer takes the body of method that cannot return normally
> ("returns" java.lang.Nothing) and actually returns? The opposite case must
> be considered too. Would a JVM error be thrown?
>

Yes.  It would be a NullPointerException at the call site (that's the only
value the verifier would let be returned from a Nothing-returning method).
The opposite case (failing to return from a method) isn't an issue.

Cheers,
Neal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091130/8b4e63ef/attachment.html 


More information about the closures-dev mailing list