jdk
jdk copied to clipboard
8043179: Lambda expression can mutate final field
(Description revised)
JDK-8043176 updated the JLS 16.1.10 to describe how within a lambda body, any variables that were DU before the lambda expression must not be considered DU at the start of the lambda block, because arbitrary code could have executed in the meantime:
No rule allows V to be definitely unassigned before a lambda body. This is by design: a variable that was definitely unassigned before the lambda body may end up being assigned to later on, so we cannot conclude that the variable will be unassigned when the body is executed.
This fix to Flow.AssignAnalyzer follows in a straightforward way: mark all variables as not DU before recursing into the lambda body.
Progress
- [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8043179: Lambda expression can mutate final field
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10381/head:pull/10381
$ git checkout pull/10381
Update a local copy of the PR:
$ git checkout pull/10381
$ git pull https://git.openjdk.org/jdk pull/10381/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10381
View PR using the GUI difftool:
$ git pr show -t 10381
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10381.diff
:wave: Welcome back archiecobbs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.
@archiecobbs The following label will be automatically applied to this pull request:
compiler
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.
Webrevs
- 12: Full - Incremental (e1cd7970)
- 11: Full - Incremental (86808b2b)
- 10: Full - Incremental (1e38c30f)
- 09: Full - Incremental (0081d190)
- 08: Full - Incremental (b1d5b3c9)
- 07: Full (06b39a59)
- 06: Full - Incremental (9352f989)
- 05: Full - Incremental (5d40607c)
- 04: Full - Incremental (703573cf)
- 03: Full - Incremental (b7bc0b6d)
- 02: Full - Incremental (6ae0fca3)
- 01: Full - Incremental (47df9c96)
- 00: Full (df8a09a1)
I've updated this pull request to include a new unit test (apologies for omitting it previously).
Also there are a couple of changes to other unit tests which get broken because this change reflects changes to the JLS spec per JDK-8043176. I'm a little unclear on precisely what the new behavior is supposed to be, but in any case the actual behavior now makes a lot more sense: basically, everything that happens in a lambda is assumed to happen some indefinite time later in the future (same as if you were instantiating the equivalent local class), so the previous errors expected by T8024809/SelfInitializerInLambdaTestb.java regarding instance field initialization are no longer errors.
In summary:
- Added new unit test
LambdaMutateFinalField.javatesting JDK-8043179 directly. - Unit test
lambda/self_initializer/T8024809/SelfInitializerInLambdaTestb.javais now obsolete. Now it compiles successfully. - Unit test
lambda/lambdaExpression/EffectivelyFinal_neg.javastill works, but no longer generates a duplicate error. I think this is a good thing? The expected test output has been updated.
With the above changes now all javac tests should succeed.
@archiecobbs Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information.
@archiecobbs Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information.
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!
@archiecobbs This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.
/open
@archiecobbs This pull request is now open
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!
/open
@archiecobbs This pull request is already open
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!
/keepalive
@archiecobbs Unknown command keepalive - for a list of valid commands use /help.
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!
/pingbot
@archiecobbs Unknown command pingbot - for a list of valid commands use /help.
@archiecobbs This change now passes all automated pre-integration checks.
ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.
After integration, the commit message for the final commit will be:
8043179: Lambda expression can mutate final field
Reviewed-by: vromero
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.
At the time when this comment was updated there had been 34 new commits pushed to the master branch:
- bf917ba6af9a69859f469a1e8056fbd32396cae4: 8304687: Move add_to_hierarchy
- 63d4afbeb17df4eff0f65041926373ee62a8a33a: 8304671: javac regression: Compilation with --release 8 fails on underscore in enum identifiers
- e2cfcfbfa90017b1b4ecbf6fb2f0f782c88456a3: 6817009: Action.SELECTED_KEY not toggled when using key binding
- af4d5600e37ec6d331e62c5d37491ee97cad5311: 8303951: Add asserts before record_method_not_compilable where possible
- c4338620b7651f4da03ce4cfddb9e5b053fddb6a: 6245410: javax.swing.text.html.CSS.Attribute: BACKGROUND_POSITION is not w3c spec compliant
- 91f407d6fe285c44bcc25c1acdf5dc0c43be0172: 8029301: Confusing error message for array creation method reference
- e73411a2354cf266ab7a5ddadfb6ea98d7eb4cd1: 8304376: Rename t1/t2 classes in com/sun/jdi/CLETest.java to avoid class duplication error in IDE
- a2d8f634de69d11d7beec5e853f710719497bfe3: 8288730: Add type parameter to Lookup::accessClass and Lookup::ensureInitialized
- 37774556da8a5aacf55884133ae936ed5a28eab2: 8302191: Performance degradation for float/double modulo on Linux
- 760c0128a4ef787c8c8addb26894c072ba8b2eb1: 8304683: Memory leak in WB_IsMethodCompatible
- ... and 24 more: https://git.openjdk.org/jdk/compare/42723dcb1862da598092bb499056940d78a8bdac...master
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well.
➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).
/integrate
@archiecobbs Your change (at version 86808b2bd0dbfe633a5bf483c56b4a6761a22849) is now ready to be sponsored by a Committer.
/sponsor
@vicente-romero-oracle The PR has been updated since the change author (@archiecobbs) issued the integrate command - the author must perform this command again.
/integrate
@archiecobbs Your change (at version e1cd797078328a1cab2a458739d1e15e92becd9c) is now ready to be sponsored by a Committer.
/sponsor
Going to push as commit c00d0885ae3c99c0ebacec0bd7de7382ee954dc1.
Since your change was applied there have been 35 commits pushed to the master branch:
- 147f3473d4cb6e0bb9edda87d571ba5088fda4a2: 8219083: java/net/MulticastSocket/SetGetNetworkInterfaceTest.java failed in same binary run on windows x64
- bf917ba6af9a69859f469a1e8056fbd32396cae4: 8304687: Move add_to_hierarchy
- 63d4afbeb17df4eff0f65041926373ee62a8a33a: 8304671: javac regression: Compilation with --release 8 fails on underscore in enum identifiers
- e2cfcfbfa90017b1b4ecbf6fb2f0f782c88456a3: 6817009: Action.SELECTED_KEY not toggled when using key binding
- af4d5600e37ec6d331e62c5d37491ee97cad5311: 8303951: Add asserts before record_method_not_compilable where possible
- c4338620b7651f4da03ce4cfddb9e5b053fddb6a: 6245410: javax.swing.text.html.CSS.Attribute: BACKGROUND_POSITION is not w3c spec compliant
- 91f407d6fe285c44bcc25c1acdf5dc0c43be0172: 8029301: Confusing error message for array creation method reference
- e73411a2354cf266ab7a5ddadfb6ea98d7eb4cd1: 8304376: Rename t1/t2 classes in com/sun/jdi/CLETest.java to avoid class duplication error in IDE
- a2d8f634de69d11d7beec5e853f710719497bfe3: 8288730: Add type parameter to Lookup::accessClass and Lookup::ensureInitialized
- 37774556da8a5aacf55884133ae936ed5a28eab2: 8302191: Performance degradation for float/double modulo on Linux
- ... and 25 more: https://git.openjdk.org/jdk/compare/42723dcb1862da598092bb499056940d78a8bdac...master
Your commit was automatically rebased without conflicts.
@vicente-romero-oracle @archiecobbs Pushed as commit c00d0885ae3c99c0ebacec0bd7de7382ee954dc1.
:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.