-
Bug
-
Resolution: Fixed
-
P4
-
8
-
b16
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. SeeJDK-8043176.
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
- duplicates
-
JDK-8180758 Illegal writes to final fields are allowed from lambdas inside a constructor
- Closed
- relates to
-
JDK-8305672 Surprising definite assignment error after JDK-8043179
- Closed
-
JDK-8294461 wrong effectively final determination by javac
- Resolved
-
JDK-8043176 16.1.10: Add DA/DU rules for lambda expressions
- Closed
(1 links to)