Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27624

Re: telling the javac that a method doesn't return at all...

Newsgroups comp.lang.java.programmer
Date 2014-02-28 16:13 -0800
References <slrnlh1gp1.g8j.avl@login.logic.tuwien.ac.at>
Message-ID <5c0f7bcf-2825-4435-b266-52465899153b@googlegroups.com> (permalink)
Subject Re: telling the javac that a method doesn't return at all...
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Andreas Leitgeb wrote:
> May be a wish to the easter bunny, or I might just have missed it
> so far (like some easter egg)
> 
> Suppose I have some "doCleanUpAndExit" method, that in the
> end either calls System.exit() or throws some Error or custom 
> RuntimeException.
> 
> I'd like the compiler to *know* that this method cannot possibly
> return, and that any code following it should be considered 
> as "unreachable" code by the compiler.

The JLS defines exactly what reachability is.

> E.g., I'd have code like:
> class Foo {
>    @DoesntReturn // tell compiler this method isn't supposed to return
>    public void doCleanUpAndExit() {
>       // compiler would barf if there was any "return"
>       //  or possible flow to end of method.
>       throw new ThisIsTheEndException();
>       // or System.exit(); which would itself need to be thusly flagged.
>    }
>    // test1() and test2() are boolean-returning methods...
> 
>    public boolean check() {
>       if ( ! test1() ) { // aww, it's all borked up
>          doCleanUpAndExit();
>          // any further code here would make the compiler barf
>       } else {
>          return ( test2() );
>       }
>       // compiler should know that flow won't ever arrive here,
>       //   so there is no way that the method doesn't return a boolean..
>    }
> }
> 
> Did I miss some annotation that already does this?

Nope.
> Is there anything like this already in the queue for 
>   future Java versions?

Not as far as I've ever seen.

Just code in accordance with the rules of reachability as they are.

-- 
Lew 

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-02-28 17:10 +0000
  Re: telling the javac that a method doesn't return at all... Lew <lewbloch@gmail.com> - 2014-02-28 16:13 -0800
    Re: telling the javac that a method doesn't return at all... Jeff Higgins <jeff@invalid.invalid> - 2014-03-01 09:12 -0500
      Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:06 +0000
  Re: telling the javac that a method doesn't return at all... Roedy Green <see_website@mindprod.com.invalid> - 2014-03-01 01:10 -0800
    Re: telling the javac that a method doesn't return at all... Jeff Higgins <jeff@invalid.invalid> - 2014-03-01 08:44 -0500
  Re: telling the javac that a method doesn't return at all... Arne Vajhøj <arne@vajhoej.dk> - 2014-03-01 22:02 -0500
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:31 +0000
      Re: telling the javac that a method doesn't return at all... Arne Vajhøj <arne@vajhoej.dk> - 2014-03-11 20:11 -0400
        Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-12 10:17 +0000
  Re: telling the javac that a method doesn't return at all... Mike Amling <mamling@chaff.us> - 2014-03-04 13:19 -0600
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:39 +0000
  Re: telling the javac that a method doesn't return at all... mike.s.schilling@gmail.com - 2014-03-04 19:30 -0800
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-09 14:33 +0000
  Re: telling the javac that a method doesn't return at all... Silvio <silvio@internet.com> - 2014-03-12 14:03 +0100
  Re: telling the javac that a method doesn't return at all... Michal Kleczek <michal_wytnijto@kleczek.org> - 2014-03-19 11:51 +0100
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-19 12:28 +0000
      Re: telling the javac that a method doesn't return at all... Michal Kleczek <michal_wytnijto@kleczek.org> - 2014-03-23 11:15 +0100

csiph-web