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

Surprising definite assignment error after JDK-8043179

XMLWordPrintable

    • b16
    • 21
    • b21
    • Verified

      javac reports the following definite assignment error after the fix for JDK-8043179. The error is surprising to me, since the lambda doesn't reference 'x' at all. Is this expected?

      $ cat T.java
      public class T {

        private final int x;

        public T() {
          try {
            Runnable r =
                () -> {
                  try {
                    return;
                  } catch (Exception e) {
                    throw new AssertionError(e);
                  }
                };
          } catch (Exception e) {
          }
          x = 42;
        }
      }

      $ javac -fullversion T.java
      javac full version "20-ea+35-2342"
      OK

      $ javac -fullversion T.java
      javac full version "21-ea+16-1326"
      T.java:17: error: variable x might already have been assigned
          x = 42;
          ^
      1 error

            acobbs Archie Cobbs
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: