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

Effectivelly final condition not enforced in guards for binding variables from the same case

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • 21
    • tools
    • b03

    Backports

      Description

        Consider this snippet of code:
        ---
        public class Test {

            public static void main(String[] args) {
                Object o = null;
                switch (o) {
                    case String s when s.isEmpty() -> {
                        s = null;
                    }
                    default -> {}
                }
            }
        }
        ---

        javac accepts this code, even though 's' is not effectively final and is used inside the guard. But, variables declared outside of the guard must be (effectively) final.

        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: