Bug in JLS specification for restriction on where a return statement is allowed.
Alex Buckley
Alex.Buckley at Sun.COM
Wed Dec 2 11:07:40 PST 2009
Hi Neal,
Yes, javac is right. I imagine all other Java compilers behave the same.
I have filed a specification bug which will be visible shortly at
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6906550.
Please note:
In cases where the JLS and javac differ, and it is clearly or likely the
JLS at fault, compiler-dev is not the appropriate reporting vehicle.
Please use the feedback form link on http://java.sun.com/docs/books/jls/
or file a defect on bugs.sun.com.
In cases where the JLS and javac differ, and it's not clear which is
right, compiler-dev is an appropriate reporting vehicle.
Alex
Neal Gafter wrote:
> Alex-
>
> JLS 14.17 says
>
> A compile-time error occurs if a |return| statement appears within an
> instance initializer or a static initializer (§8.7)
> <http://java.sun.com/docs/books/jls/third_edition/html/classes.html#39245>.
>
> However, javac allows a return statement within an instance or static
> initializer if there is an intervening nested inner class with a method.
>
> *static { // static initializer*
> * class X {*
> * void foo() {*
> * return; // yet return allowed within it*
> * }*
> * }*
> *}*
>
> I believe this is a bug in the specification.
>
> Cheers,
> Neal
>
More information about the compiler-dev
mailing list