-
Bug
-
Resolution: Fixed
-
P3
-
8
Chapter 16 is missing rules for handling DA/DU analysis of lambda expressions. The existing general expression rules are ambiguous (what are the subexpressions of a lambda?) and not completely correct.
1) A variable is DA/DU after a lambda expression if it is DA/DU before -- lambda expression evaluation never triggers a variable assignment. The contents of the body are irrelevant.
2) To analyze the lambda body (either an expression or a block), a variable is DA before the body if it is DA before the lambda expression. This is sort of implied by the existing rules, but not very well.
3) To detect assignments to blank final fields, a field is *never* DU before the lambda body. (The intuition is that the timing of the body invocation is unknown, so we don't know whether the variable has been initialized or not.)
javac implements (1) and (2) but not (3). Because it does not implement (3), it allows final fields to be mutated by lambda bodies -- clearly an intolerable state of affairs (see separate javac bug).
1) A variable is DA/DU after a lambda expression if it is DA/DU before -- lambda expression evaluation never triggers a variable assignment. The contents of the body are irrelevant.
2) To analyze the lambda body (either an expression or a block), a variable is DA before the body if it is DA before the lambda expression. This is sort of implied by the existing rules, but not very well.
3) To detect assignments to blank final fields, a field is *never* DU before the lambda body. (The intuition is that the timing of the body invocation is unknown, so we don't know whether the variable has been initialized or not.)
javac implements (1) and (2) but not (3). Because it does not implement (3), it allows final fields to be mutated by lambda bodies -- clearly an intolerable state of affairs (see separate javac bug).
- relates to
-
JDK-8043179 Lambda expression can mutate final field
- Resolved
-
JDK-8167140 16: Clean up structure of DA/DU chapter
- Open
-
JDK-8025762 8.3.3: Clarify that a field cannot be referenced in its own initializer
- Closed
-
JDK-8042405 Can't compile Lambda referencing final variable initialized on constructor
- Closed
-
JDK-8289777 javac does not see a problem when Eclipse emits a 'blank final field may not have been initialized' error
- Closed