RFR: 8348100: Tooltips cannot be instantiated on background thread
Kevin Rushforth
kcr at openjdk.org
Fri Feb 7 18:40:17 UTC 2025
On Thu, 6 Feb 2025 18:35:06 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> Navigating up the parent hierarchy during CSS processing in a background thread encounters a null parent, causing a NPE.
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`.
modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java line 205:
> 203: if (parent == null) {
> 204: return;
> 205: }
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.
-------------
PR Review: https://git.openjdk.org/jfx/pull/1696#pullrequestreview-2602481137
PR Review Comment: https://git.openjdk.org/jfx/pull/1696#discussion_r1946970797
More information about the openjfx-dev
mailing list