-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8294461: wrong effectively final determination by javac #10856
Conversation
👋 Welcome back archiecobbs! A progress list of the required criteria for merging this PR into |
@archiecobbs The following label will be automatically applied to this pull request:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks sensible
@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:
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 6 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the 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 |
Thanks for the review. |
/integrate |
@archiecobbs |
/sponsor |
Going to push as commit b8ad6cd.
Your commit was automatically rebased without conflicts. |
@vicente-romero-oracle @archiecobbs Pushed as commit b8ad6cd. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Should this change have a (retroactive) CSR and/or release note? |
There shouldn't be any spec change implied by this change. From my understanding, the compiler was not following the spec, which says that the variable Regarding release notes, I'll let someone else who has more familiarity with the release process comment on that. |
well on similar cases we have done a CSR, I didn't realize during the review, sorry. I guess a CSR should probably be enough. I can help reviewing it. The reason @jddarcy is proposing the CSR is, IMO, because even though the spec didn't change, the universe of acceptable Java programs have changed, more in this case when that universe have been reduced. This is one of the situations for which a CSR should be created. @jddarcy not sure about the release notes but I if you think so I have no issues. I will file the CSR |
Adding some additional context, there CSR reviews both specification changes and behavioral changes considered to have sufficiently high compatibility impact. This change renders code that previously (if erroneously) compiled into a compilation error, which is a source compatibility concern. (Changing code that compiles into code that doesn't compile is considered a more serious change than the reverse.) Offhand, I don't know how often such coding patterns may appear in practice; we should some internal tooling which can help gauge that. A modification that may be suggested is only doing the updated check for source level 20 and higher. HTH |
Thanks for the clarifications, now I understand better the rationale. Seems this example might be a good one to add to the spec in a non-normative/informational blurb, to demonstrate (a) how "JLS unreachable" doesn't always equal "flow analysis unreachable", and/or (b) how "effectively final" can fail because of statements that are "flow analysis unreachable". |
This bug involves DA/DU analysis and the concept of "effectively final".
Here's the test case, which the compiler currently but incorrectly accepts:
For the purposes of "effectively final", it doesn't matter whether an assignment statement that makes a variable no longer effectively final is actually reachable or not. In cases like the
i++
above, a statement can be actually unreachable yet not "unreachable" according to the JLS, and so it does not generate an "unreachable statement" compiler error (which would otherwise hide this bug).JLS §4.12.4 states:
So clearly
i
is not effectively final.However, the way we calculate effective finality does not involve actually looking for increment/decrement operators. Instead, it's determined during DA/DU analysis: non-final variables have an
EFFECTIVELY_FINAL
flag which is initialized totrue
and then cleared if/when we encounter contrary evidence - e.g., an assignment when not DU.For simplicity, the DA/DU analysis works like this:
These are reasonable. However, it means this clause of JLS §4.12.4 effectively applies:
The bug with the current code is that when we see an assignment to a variable with the
EFFECTIVELY_FINAL
flag still set, we clear the flag if the variable is not DU, but we are not clearing the flag if the variable is DA, as required above. This happens with thei++
statement because, by virtue of it being actually unreachable,i
is both DA and DU before that statement.This patch corrects that omission.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10856/head:pull/10856
$ git checkout pull/10856
Update a local copy of the PR:
$ git checkout pull/10856
$ git pull https://git.openjdk.org/jdk pull/10856/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10856
View PR using the GUI difftool:
$ git pr show -t 10856
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10856.diff