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

Compiler reports AssertionError for conditional operator ? : and pattern matching for instanceof

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 14
    • Fix Version/s: 14
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b26

      Description

      Compiler is reporting AssertionError when pattern matching for instanceof is used in the conditional operator ? :

      Sample Code:

      public class TestPattern {
       
            public static void main(String[] args) {
       
                Object ax = "";

                boolean result = (ax instanceof String a) ? (ax instanceof String a) : (! (ax instanceof String a));
       
                System.out.println("result = " + result);

            }
       }

      Result: AssertionError

      Expected result: result = true


      Compiler log is attached below:

        Attachments

          Activity

            People

            • Assignee:
              jlahoda Jan Lahoda
              Reporter:
              rchandra Ravi Chandra
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: