Request for Review: 7116914 (Miscellaneous warnings (sun.text))
Stuart Marks
stuart.marks at oracle.com
Fri Dec 2 22:04:17 UTC 2011
On 12/2/11 12:25 PM, Mike Duigou wrote:
> UnicodeSet.java:
> - I confirmed, just to be sure, that the added 'break;' statements have no effect.
A stylistic comment, not directly relevant to warnings fixes.
The compiler warns about possible fall-through to the next case, but the
locations where "break" appears to be missing all follow calls to the
syntaxError() method. Turns out this method always throws an exception, but the
compiler isn't as smart as Mike :-) and so it doesn't realize that control can
never return to the switch statement to fall through to the next case. Adding a
break statement shuts up the compiler but the statement is in fact unreachable.
Another point is that, to the programmer's eye, it really does look like there
is a missing break statement.
An alternative way to structure this is to have syntaxError() return an
exception instead of throwing it, relying on the caller to do the throw. This
is a bit unusual, but it makes things read much better:
switch (something) {
case 1:
...
throw syntaxError(...);
case 2:
...
}
This makes it clear to the compiler and the programmer that there is no fall
through. (Hat tip to Tom Hawtin for this.)
s'marks
More information about the core-libs-dev
mailing list