[JEP 325 Switch Expression] switch labeled block completion issue?

Manoj Palat manojnp.java at gmail.com
Wed Nov 28 04:19:16 UTC 2018

Hi Joe, all,
The following program compiles without errors.

package se2;

import java.io.IOException;
public class X {
public static int twice(int i) throws IOException {
int k = switch (i) {
case 1 -> {
// break 1;
case 2 -> {
// break 2;
  default ->  10;
return k;
public static void main(String[] args) {
try {
} catch (IOException e) {
//do nothing;

$ javac12 --enable-preview -source 12 se2/X.java
Note: se2\X.java uses preview language features.
Note: Recompile with -Xlint:preview for details.

$ java12 --enable-preview se2/X

Other details:
$ uname -a
CYGWIN_NT-6.1 XXXXX 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64 Cygwin

The output of the program is given above – essentially a fall-through akin
to a switch statement’s expected behavior.
However, From JLS 12 15.29.1,* “Given a switch expression, if the switch
block consists of switch labeled rules, then it is a compile-time error if
any switch labeled block can complete normally. If, on the other hand, the
switch block consists of switch labeled statement groups, then it is a
compile-time error if either the last statement in the switch block can
complete normally, or the switch block includes one or more switch labels
at the end.” *

>From the above I expected a compilation error to be shown since the case 1
and case 2 arms can complete normally without a break expression.

Is this an error in Javac or is it a wrong interpretation of "complete
normally" in the spec on my part?
 (Once the break expressions are uncommented, the switch expression returns
the appropriate  values which is of course the correct behavior.) I am
using ea 20 for this.

Manoj Palat
Eclipse Java Dev,

PS: I had sent this mail yesterday from my IBM official id, but I don;t see
that mail in the mailing list yet - hence resending from personal id.

From: "Joseph D. Darcy" <joe.darcy at oracle.com>
To: jdk-dev <jdk-dev at openjdk.java.net>
Date: 11/27/2018 06:29 AM
Subject: Reminder: submit CSRs for JDK 12 with sufficient time ahead of
rampdown 1 milestone
Sent by: "jdk-dev" <jdk-dev-bounces at openjdk.java.net>


As a reminder, per the JDK 12 schedule
rampdown phase 1 of the
release is coming up in a few weeks on Dec. 13, 2018.

If you are planning to get a change into JDK 12 before the rampdown 1
milestone and the change requires a CSR, the CSR needs to be an the
Approved state before the change is pushed. The nominal review time of
the CSR is one week. Note this is the time to review, not necessarily
the time to approve. As with code reviews, the CSR process can provide
feedback which has to be acted upon before a request is approved.

Please plan accordingly; cheers,

CSR Lead

More information about the jdk-dev mailing list