[jdk17] RFR: 8270006: Switches with 'case null:' should be exhaustive
Jan Lahoda
jlahoda at openjdk.java.net
Wed Jul 7 17:18:53 UTC 2021
On Wed, 7 Jul 2021 12:37:46 GMT, Rémi Forax <forax at openjdk.org> wrote:
>> Code like:
>>
>> void exhaustiveAndNull(String s) {
>> switch (s) {
>> case null: break;
>> }
>> }
>>
>>
>> should be rejected, because the switch is no exhaustive, but it is a "new" switch. (Note that this not a problem for switch expressions, which always have to be exhaustive.)
>
> test/langtools/tools/javac/patterns/SwitchErrors.java line 192:
>
>> 190: case null: break;
>> 191: }
>> 192: }
>
> The other possible new syntax is "case default", but there is no error because it's exhaustive.
>
>
> void exhaustiveCaseDefaultNoError(String s) {
> switch (s) {
> case default: break;
> }
> }
Correct, there are tests that verify (at least as a side-effect) that `case default` is total in `test/langtools/tools/javac/patterns/CaseDefault.java`.
-------------
PR: https://git.openjdk.java.net/jdk17/pull/224
More information about the compiler-dev
mailing list