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
-----
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
- relates to
-
JDK-8289171 Blank final field 'dialog' may not have been initialized in scene.control.Dialog:521
- Resolved
-
JDK-8043176 16.1.10: Add DA/DU rules for lambda expressions
- Closed
-
JDK-8193904 Uninitialized final field access and qualified this
- Open