jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8043179: Lambda expression can mutate final field

Open archiecobbs opened this issue 3 years ago • 5 comments

(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

archiecobbs avatar Sep 21 '22 23:09 archiecobbs

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

bridgekeeper[bot] avatar Sep 21 '22 23:09 bridgekeeper[bot]

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

openjdk[bot] avatar Sep 21 '22 23:09 openjdk[bot]

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:

With the above changes now all javac tests should succeed.

archiecobbs avatar Sep 24 '22 23:09 archiecobbs

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

openjdk-notifier[bot] avatar Sep 25 '22 00:09 openjdk-notifier[bot]

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

openjdk-notifier[bot] avatar Oct 18 '22 17:10 openjdk-notifier[bot]

@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!

bridgekeeper[bot] avatar Nov 17 '22 05:11 bridgekeeper[bot]

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

bridgekeeper[bot] avatar Dec 16 '22 00:12 bridgekeeper[bot]

/open

archiecobbs avatar Dec 16 '22 00:12 archiecobbs

@archiecobbs This pull request is now open

openjdk[bot] avatar Dec 16 '22 00:12 openjdk[bot]

@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!

bridgekeeper[bot] avatar Jan 16 '23 20:01 bridgekeeper[bot]

/open

archiecobbs avatar Jan 19 '23 17:01 archiecobbs

@archiecobbs This pull request is already open

openjdk[bot] avatar Jan 19 '23 17:01 openjdk[bot]

@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!

bridgekeeper[bot] avatar Feb 16 '23 21:02 bridgekeeper[bot]

/keepalive

archiecobbs avatar Feb 17 '23 00:02 archiecobbs

@archiecobbs Unknown command keepalive - for a list of valid commands use /help.

openjdk[bot] avatar Feb 17 '23 00:02 openjdk[bot]

@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!

bridgekeeper[bot] avatar Mar 17 '23 04:03 bridgekeeper[bot]

/pingbot

archiecobbs avatar Mar 17 '23 13:03 archiecobbs

@archiecobbs Unknown command pingbot - for a list of valid commands use /help.

openjdk[bot] avatar Mar 17 '23 13:03 openjdk[bot]

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

openjdk[bot] avatar Mar 21 '23 14:03 openjdk[bot]

/integrate

archiecobbs avatar Mar 21 '23 15:03 archiecobbs

@archiecobbs Your change (at version 86808b2bd0dbfe633a5bf483c56b4a6761a22849) is now ready to be sponsored by a Committer.

openjdk[bot] avatar Mar 21 '23 15:03 openjdk[bot]

/sponsor

vicente-romero-oracle avatar Mar 23 '23 03:03 vicente-romero-oracle

@vicente-romero-oracle The PR has been updated since the change author (@archiecobbs) issued the integrate command - the author must perform this command again.

openjdk[bot] avatar Mar 23 '23 03:03 openjdk[bot]

/integrate

archiecobbs avatar Mar 23 '23 14:03 archiecobbs

@archiecobbs Your change (at version e1cd797078328a1cab2a458739d1e15e92becd9c) is now ready to be sponsored by a Committer.

openjdk[bot] avatar Mar 23 '23 14:03 openjdk[bot]

/sponsor

vicente-romero-oracle avatar Mar 23 '23 15:03 vicente-romero-oracle

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.

openjdk[bot] avatar Mar 23 '23 16:03 openjdk[bot]

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

openjdk[bot] avatar Mar 23 '23 16:03 openjdk[bot]