-
Notifications
You must be signed in to change notification settings - Fork 505
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
8350048: Enforce threading restrictions for show and hide methods in Window, Control, and Skin #1717
8350048: Enforce threading restrictions for show and hide methods in Window, Control, and Skin #1717
Conversation
👋 Welcome back angorya! A progress list of the required criteria for merging this PR into |
@andy-goryachev-oracle 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
/reviewers 2 reviewers |
@kevinrushforth |
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. @andy-goryachev-oracle please create a CSR request for issue JDK-8350048 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Reviewers: @kevinrushforth @arapte |
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.
The API doc changes look good, although I noted a couple additional changes that are needed.
The API docs for Dialog::hide
should also be documented to throw ISE (since it calls close()
directly the implementation is fine)
The API docs for Stage::close
should also be documented to throw ISE (since it calls hide()
directly the implementation is fine)
For ComboBoxBase
, were you going to get rid of the word "aspect" in the opening sentence "... display the popup aspect of the user interface."? I think that's a little awkward even with that word removed. Maybe it could just be: "... display the popup associated with this control."
As for the implementation, There are a few places where the skin will call hide(), and I can't tell by just looking at the code that they are all guaranteed to be on the FX app thread.
For example, I recommend checking the following:
MenuBarSkin
line 799ComboBoxListViewSkin
line 199
There may be others.
* | ||
* This test ensures that the threading restrictions are in place where required. | ||
*/ | ||
@TestMethodOrder(MethodOrderer.MethodName.class) |
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.
This is unnecessary (and not a usual practice).
|
||
test(TPopupWindow::new, (p) -> p.show(stage)); | ||
test(TPopupWindow::new, (p) -> p.show(stage, 0, 0)); | ||
test(TPopupWindow::new, (p) -> p.show(contentPane, 0, 0)); |
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.
It's probably worth adding a test for hide
when it isn't showing (like you've done for other objects).
Util.runAndWait(() -> { | ||
p.show(); | ||
}); | ||
p.hide(); // do we need to fail early here, or only when showing? |
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.
We should fail early (although this comment seems misplaced, since it is the case where it is showing).
} | ||
|
||
@Test | ||
@Timeout(value = 1, unit = TimeUnit.DAYS) |
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.
Um, 1 DAY???
Seriously, though: Remove the timeout (it isn't needed or wanted).
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.
checked in by mistake
public void show() { | ||
if (!isDisabled()) setShowing(true); | ||
Toolkit.getToolkit().checkFxUserThread(); | ||
if (!isDisabled()) { | ||
setShowing(true); | ||
} | ||
} |
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.
Would it be a good idea to move the check Toolkit.getToolkit().checkFxUserThread();
to a new method show()
in Parent class Control
? And may be similarly to Parent classes of other classes.
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.
No, we don't want to add a new public show
method to Control
since it is only a very few controls that have the concept of showing a popup.
I think it should be sufficient to mention the exception in the actual methods where the check is done, such as |
I'm not talking about docs here. What I meant that if the code in question is ever executed on a background thread such that hide is called, this will now cause an exception at runtime. I don't know whether it is possible, but it isn't immediately obvious that this can't happen on a background thread -- at least not for the two cases I mentioned. In fact, I'm pretty sure that at least the second case (ComboBoxListViewSkin line 199) is possible.
I suspect that the following sequence of operations, all on a background thread, will trigger the exception:
A solution might be to check whether the combobox is showing before hiding it.
And, if the code in MenuBarSkin is a problem, then something like this might be in order:
Similarly, I think this listener in
|
The updated docs look good. Go ahead and create the CSR. |
created CSR https://bugs.openjdk.org/browse/JDK-8350962 |
ComboBoxListViewSkin - thanks for the suggestion! MenuBarSkin - is a bit more complex case because of the interaction with the system menu We probably should disallow creating MenuBars in background thread (similar to Window, WebView, and HtmlEditor) in the constructor. What do you think? |
Created https://bugs.openjdk.org/browse/JDK-8350976 for the MenuBarSkin. |
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.
All looks good now.
Have you done a headful test run?
@@ -1183,6 +1183,8 @@ public void toBack() { | |||
/** | |||
* Closes this {@code Stage}. | |||
* This call is equivalent to {@code hide()}. | |||
* @throws IllegalStateException if this method is called on a thread | |||
* other than the JavaFX Application Thread. |
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.
Minor: add a blank line before @throws
. I also think it's easier to read docs when multi-line text for a javadoc tag is indented, either by four spaces or lined up with the beginning of the first line of text (i.e. with the beginning of IllegalStateException
).
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.
good idea, even though it does not affect generated javadoc.
will do next time, to avoid re-setting the approvals ;-)
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.
will do next time, to avoid re-setting the approvals ;-)
I'll re-approve if you decide to do the changes anyway.
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.
it is not required, and the code is inconsistent (Stage:472) ... but ok.
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.
Can you do it for the other changed docs also?
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.
The general policy is to avoid unrelated changes and expanding the scope.
A proper way to address that would be to create a JBS and do a wholesale bulk edit, not sure if it's worth it though.
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.
You've added the same javadoc tag in 20 different places. All I'm asking is that you do the change that you did in this particular place in all of the other places too.
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.
I misunderstood, sorry. Done.
/integrate |
Going to push as commit b5f76ad. |
@andy-goryachev-oracle Pushed as commit b5f76ad. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
IllegalStateException
can get thrown, such as hide() and show()ComboBoxBase::show
TestThreadingRestrictions
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1717/head:pull/1717
$ git checkout pull/1717
Update a local copy of the PR:
$ git checkout pull/1717
$ git pull https://git.openjdk.org/jfx.git pull/1717/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1717
View PR using the GUI difftool:
$ git pr show -t 1717
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1717.diff
Using Webrev
Link to Webrev Comment