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

javac may crash on a record pattern with too few components

    XMLWordPrintable

Details

    • b10

    Backports

      Description

        Consider code like:
        ---
        public class Err {

            record R(String x) {}

            public void(Object obj) {

                switch(obj) {

                    case R(var v, ) -> 1;

                }

            }

        }
        ---

        javac may crash on this code:
        ---
        $ ./build/linux-x86_64-server-release/images/jdk/bin/javac -XDdev -XDshould-stop.at=FLOW /tmp/Err.java
        /tmp/Err.java:5: error: <identifier> expected
            public void(Object obj) {
                       ^
        /tmp/Err.java:9: error: illegal start of type
                    case R(var v, ) -> 1;
                                  ^
        /tmp/Err.java:9: error: not a statement
                    case R(var v, ) -> 1;
                                       ^
        /tmp/Err.java:9: error: incorrect number of nested patterns
                    case R(var v, ) -> 1;
                         ^
          required: String
          found: String,<any>
        4 errors
        An exception has occurred in the compiler (22-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
        java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
                at jdk.compiler/com.sun.tools.javac.comp.Flow.makePatternDescription(Flow.java:3483)
        ...
        ---

        Attachments

          Issue Links

            Activity

              People

                jlahoda Jan Lahoda
                jlahoda Jan Lahoda
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: