Skip to content
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

8348100: Tooltips cannot be instantiated on background thread #1696

Conversation

andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Feb 6, 2025

Root Cause

navigating up the parent hierarchy during CSS processing in a background thread encounters a null parent, causing the NPE. The null parent comes from a static Toolkit.BEHAVIOR field.

Solution

avoid that code path if not in the fx application thread.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8348100: Tooltips cannot be instantiated on background thread (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1696/head:pull/1696
$ git checkout pull/1696

Update a local copy of the PR:
$ git checkout pull/1696
$ git pull https://git.openjdk.org/jfx.git pull/1696/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1696

View PR using the GUI difftool:
$ git pr show -t 1696

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1696.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 6, 2025

👋 Welcome back angorya! 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.

@openjdk
Copy link

openjdk bot commented Feb 6, 2025

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

8348100: Tooltips cannot be instantiated on background thread

Reviewed-by: kcr, mstrauss

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 master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Feb 6, 2025

⚠️ @andy-goryachev-oracle This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review February 6, 2025 18:49
@openjdk openjdk bot added the rfr Ready for review label Feb 6, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 6, 2025

Webrevs

@andy-goryachev-oracle
Copy link
Contributor Author

/reviewers 2

@openjdk
Copy link

openjdk bot commented Feb 6, 2025

@andy-goryachev-oracle
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@kevinrushforth kevinrushforth self-requested a review February 6, 2025 19:42
Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the root cause of the problem is in Tooltip::getStyleableParent, which does not return a stable result when called from a background thread. The implementation does this:

        if (BEHAVIOR.hoveredNode == null) {
            return super.getStyleableParent();
        }
        return BEHAVIOR.hoveredNode;

Where BEHAVIOR is a static field of Tooltip.

This might be a better fix:

    @Override public Styleable getStyleableParent() {
        if (!Platform.isFxApplicationThread() || BEHAVIOR.hoveredNode == null) {
            return super.getStyleableParent();
        }
        return BEHAVIOR.hoveredNode;
    }

and then you don't even need the null checks you added to CssStyleHelper.

Comment on lines 203 to 205
if (parent == null) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does prevent the exception, I think this is fixing a symptom rather than the root cause. The only reason that parent can ever be null here and in the other place you added the null check is that Tooltip::getStyleableParent is returning a different answer between the time it is called to calculate depth and the time it is used here in a loop. This is happening because Tooltip::getStyleableParent uses static state that is only valid when on the FX application thread.

@andy-goryachev-oracle
Copy link
Contributor Author

BEHAVIOR is a static field of Tooltip.

You are right, this is the root cause and a better fix! (What was I thinking? The ticket points to it directly in the description).

Fun fact: one can add junit5 annotation @RepeatedTest(value = 5) to a test to make it repeat.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. I confirm that the new test fails reliably without the fix and passes with the fix.

import com.sun.javafx.beans.IDProperty;
import com.sun.javafx.css.StyleManager;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.stage.PopupWindowHelper;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of import noise for such a small patch...

@openjdk openjdk bot added the ready Ready to be integrated label Feb 9, 2025
@andy-goryachev-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 10, 2025

Going to push as commit 3ce3af0.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 10, 2025
@openjdk openjdk bot closed this Feb 10, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Feb 10, 2025
@openjdk
Copy link

openjdk bot commented Feb 10, 2025

@andy-goryachev-oracle Pushed as commit 3ce3af0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8348100.tootlip.thread.safety branch February 10, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants