Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8226510

No compilation error when switch expression has no result expressions

    XMLWordPrintable

Details

    • b28
    • Verified

    Backports

      Description

        The below code should throw a compilation error as there is no result expression for the switch expression. However, the compilation goes through successfully.

        public class SwitchTest {

            public static void main(String[] args) throws MyException {
                int i = 0;
                int a = switch (i) {
                    default -> throw new MyException();
                };
                System.out.println(a);
            }

        }

        class MyException extends Exception {

        }

        Attachments

          Issue Links

            Activity

              People

                jlahoda Jan Lahoda
                vkhatri Vinod Khatri
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: