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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 22
    • Affects Version/s: 21
    • Component/s: tools
    • b03

        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.

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

                Created:
                Updated:
                Resolved: