Skip to content

8388277: [REDO] Looked-up color fails for -fx-background-color in JavaFX CSS file - #2225

Open
Maran23 wants to merge 2 commits into
openjdk:masterfrom
Maran23:8388277-REDO]-Looked-up-color-fails-for--fx-background-color-in-JavaFX-CSS-file
Open

8388277: [REDO] Looked-up color fails for -fx-background-color in JavaFX CSS file#2225
Maran23 wants to merge 2 commits into
openjdk:masterfrom
Maran23:8388277-REDO]-Looked-up-color-fails-for--fx-background-color-in-JavaFX-CSS-file

Conversation

@Maran23

@Maran23 Maran23 commented Jul 27, 2026

Copy link
Copy Markdown
Member

Another much better try to fix the issue.
I recommend to read: #2201 first. All tests from there are included.
I added some new ones that succeed before and after, a first step for more CSS tests as discussed in: #2218 (comment)

My new idea is now the following constraint, which I think is also a much better approach:

  • A CssStyleHelper always has a correct firstStyleableAncestor. We can at any time trust and rely on it.
  • We will also reuse the existing loop for the isUserSetFont check to improve the performance a bit

Implementation:

  • A new private CssHelperState is introduced on Node. We need to know whether we can trust the styleHelper.
  • Not every Node has a styleHelper - it is only created when needed, so we can not attach the flag in there

This fixes the issue while a deep (optionally unstyled) scene graph has no performance penality.
The approach is similar than my previous PR, but more smart. And with the set constraint mentioned above.


I do think we can improve the CssStyleHelper more. But for another day.
Maybe at one point, with more tests and when all requirements are clear, we can find a way without CssHelperState and without creating an empty CssStyleHelper just to hold trigger states (because of that, we need to check styleHelper.cacheContainer != null a lot of times).

/issue add JDK-8187955



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)

Issues

  • JDK-8388277: [REDO] Looked-up color fails for -fx-background-color in JavaFX CSS file (Bug - P4)
  • JDK-8187955: CssStyleHelper : recursion in isUserSetFont() can be avoided (Bug - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2225

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

openjdk Bot commented Jul 27, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot added the rfr Ready for review label Jul 27, 2026
@openjdk

openjdk Bot commented Jul 27, 2026

Copy link
Copy Markdown

@Maran23
Adding additional issue to issue list: 8187955: CssStyleHelper : recursion in isUserSetFont() can be avoided.

@openjdk

openjdk Bot commented Jul 27, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: rfr. This can be overridden with the /reviewers command.

@mlbridge

mlbridge Bot commented Jul 27, 2026

Copy link
Copy Markdown

Webrevs

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please resolve the merge conflict.

…REDO]-Looked-up-color-fails-for--fx-background-color-in-JavaFX-CSS-file

# Conflicts:
#	modules/javafx.graphics/src/test/java/test/javafx/scene/CssStyleHelperTest.java
@subhramit

subhramit commented Aug 2, 2026

Copy link
Copy Markdown

Our project JabRef is currently dependent on this fix for a critical performance bug report.
Would really appreciate if it could be expedited.

@kevinrushforth

Copy link
Copy Markdown
Member

Our project JabRef is currently dependent on this fix for a critical performance bug report. Would really appreciate if it could be expedited.

GIven that the earlier version caused a regression, and that this touches an area of the code that is particularly tricky, it will need sufficient time to review and test it. It will then go into jfx28 and is unlikely to be backported, given the risk, at least not right away.

*/
private static boolean isStyleableAncestor(Node parentNode) {
if (parentNode.cssHelperState == Node.CssHelperState.STALE) {
parentNode.cssHelperState = Node.CssHelperState.RESOLVED_EARLY;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there might be a problem here: this code sets RESOLVED_EARLY before creating the styleHelper. createStyleHelper() can invoke application listeners that might, for example, add new nodes and force applyCss() immediately. The re-entrance descendants see RESOLVED_EARLY and trust the old, stale, styleHelper.

would it make sense to add another state, or perhaps move the state into styleHelper ?

Styleable parent = node;
int depth = 0;
while(parent != null) {
while (parent != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there might be potential quadratic execution time here.

imagine a long chain of nodes

root
  + node1
      + node2
         ...
            + nodeN
  • start by adding a child to nodeN, this makes the entire chain dirty.
  • change style class in all the nodes in the chain
  • add a second child to nodeN

adding the second child recursively rebuilds every stale ancestor, walking all the way to the root.

}

if (node.styleHelper != null) {
setFirstStyleableAncestor(node.styleHelper, styleableAncestor);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this changes the existing helper's ancestor unconditionally. the helper might contain stale styles (especially during style or hierarchy updates from within the listeners)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfr Ready for review

Development

Successfully merging this pull request may close these issues.

4 participants