The Definitely Unassigned analysis fails to detect the error in a lambda expression initializing a blank final field.
public class LambdaFieldInit {
private final String x;
public LambdaFieldInit() {
Runnable r1 = () -> x = "hi";
x = "abc";
r1.run();
System.out.println(x);
}
public static void main(String... args) { new LambdaFieldInit(); }
}
Expected: compiler error in the lambda body's assignment to 'x'
Actual: compiles, prints "hi" at runtime
It needs to be specified that 'x' is not DU in the body of the lambda; currently, that specification is missing. See JDK-8043176.