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

Assertion error in value break statement with conditional operator in switch expression

    XMLWordPrintable

Details

    • b23
    • Verified

    Description

      The following code examples shows compile time error (java.lang.AssertionError):
      In the following examples, a result expressions with a conditional operator is used as value break statement in the switch statement.

      Code 1:

      public class Test {
          public static void main(String[] args) {

              boolean b;

              b = switch(1){
                  case 1: break true && true;
                  default: break false;
              };

              System.out.println(b);
          }
      }

      Code 2:

      public class Test {
          public static void main(String[] args) {

              boolean b;

              b = switch(1){
                  case 1: break true || true;
                  default: break false;
              };

              System.out.println(b);
          }
      }

      Code 3:

      public class SwitchTest {
          public static void main(String[] args) {

              int a =0;
              boolean b = true;

              boolean b1 = switch(a){
                  case 0: break b ? true : false;
                  default: break false;
              };

              System.out.println(b1);
          }
      }

      Please find the error log as attachment.

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            rchandra Ravi Chandra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: