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

16.1.10: Add DA/DU rules for lambda expressions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8
    • specification

      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).

            abuckley Alex Buckley
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: