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

javac does not see a problem when Eclipse emits a 'blank final field may not have been initialized' error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 20
    • None
    • tools
    • None
    • generic
    • generic

      This simple code generates an error in Eclipse (Version: 2022-06 (4.24.0)), but not in javac (see related issue JDK-8289171 in javafx).

      -----
      package goryachev.bugs;

      import java.lang.reflect.Field;

      public class TestNullFinal {
          private
          // uncomment to cause a 'blank final field may not have been initialized' error in Eclipse
          //final
          A isNull;
          
          public TestNullFinal() {
              isNull = new A("constructor");
              System.out.println("test=" + test);
          }
          
          public static void main(String[] args) {
              new TestNullFinal();
          }
          
          private Runnable runnable = () -> {
              // ERROR: blank final field may not have been initialized
              isNull.hashCode();
          };
          
          private Object test = isNullValue();
          
          protected Object isNullValue() {
              return (isNull);
          }
          
          protected static class A {
              public A(String text) {
                  System.out.println(text);
              }
          }
      }

      -----

      To reproduce, uncomment line 8 (// final).

      The problem is further illustrated by running the test case as is, notice that the variable isNull when the 'test' field is initialized:

      stderr output:
      constructor
      test=null

            jlahoda Jan Lahoda
            angorya Andy Goryachev
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: