JDK-8237469 : Inherited styles don't update when node is moved
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 10,openjfx11,openjfx13,openjfx14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-01-17
  • Updated: 2020-11-06
  • Resolved: 2020-02-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx11.0.10Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
When moving a node from one branch of the scene graph to another, under certain circumstances a new style helper will not be created for that node and it will retain styles from when it was in the previous branch.

The types of styles affected are fonts, inheritable styles such as visibility, and css variables.

The issue is reproducible following these steps:

"Create a scenegraph

                 R
         .-----+-----.
         A             B
   .----+----.
   C          D

Where C and D are Labels. Then set a font style on A and a different font style on B. C and D should pick up the font style of A. Then move D to B and see if it still has A's font style."

package test.javafx.scene;

import com.sun.javafx.css.StyleManager;
import javafx.stage.Stage;
import com.sun.javafx.tk.Toolkit;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import javafx.css.CssParser;
import javafx.css.Stylesheet;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import static org.junit.Assert.assertNull;

import org.junit.Before;
import org.junit.Test;

public class CSSStyleHelperTest {

    private Scene scene;
    private Stage stage;
    private StackPane root;

    @Before
    public void setup() {
        root = new StackPane();
        scene = new Scene(root);
        stage = new Stage();
        stage.setScene(scene);

        StyleManager sm = StyleManager.getInstance();
        sm.userAgentStylesheetContainers.clear();
        sm.platformUserAgentStylesheetContainers.clear();
        sm.stylesheetContainerMap.clear();
        sm.cacheContainerMap.clear();
        sm.hasDefaultUserAgentStylesheet = false;
    }

    @Test
    public void movingNodeToDifferentBranchGetsNewFontStyleTest() throws IOException {
        Stylesheet stylesheet = null;
        root.getStyleClass().add("root");
        //               R
        //         .-----+-----.
        //         A           B
        //    .----+----.      .
        //    C         D      E
        //Where C and D are Labels. Then I'd set a font style on A and a different font style on B.
        //C and D should pick up the font style of A. Then move D to B and see if it still has A's
        //font style.
        stylesheet = new CssParser().parse(
                "movingNodeToDifferentBranchGetsNewFontStyleTest",
                ".root {}\n"
                + ".a { -fx-font-style: italic; }\n"
                + ".b { -fx-font-family: normal; }\n"
        );
        StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
        Pane A = new Pane();
        A.getStyleClass().add("a");
        Pane B = new Pane();
        B.getStyleClass().add("b");
        Text C = new Text("C");
        Text D = new Text("D");
        Text E = new Text("E");
        root.getChildren().addAll(A, B);
        A.getChildren().addAll(C, D);
        B.getChildren().add(E);
        stage.show();
        Toolkit.getToolkit().firePulse();
        assertEquals("Italic", C.getFont().getStyle());
        assertEquals("Italic", D.getFont().getStyle());
        assertNull(E.getFont().getStyle());

        B.getChildren().add(D); //move D
        Toolkit.getToolkit().firePulse();
        assertEquals("Italic", C.getFont().getStyle());
        assertNull(D.getFont().getStyle());
        assertNull(E.getFont().getStyle());
    }
}

The issue appears to have been introduced by https://bugs.openjdk.java.net/browse/JDK-8090462
Comments
Changeset: 6968e38d Author: Dean Wookey <dwookey@openjdk.org> Committer: Kevin Rushforth <kcr@openjdk.org> Date: 2020-02-06 13:16:16 +0000 URL: https://git.openjdk.java.net/jfx/commit/6968e38d
06-02-2020

I suspect that this is also the root cause for JDK-8234877, which I tracked down as being a regression caused by JDK-8090462. Can you test this, and if it is, then you can closed JDK-8090462 as a duplicate of this bug?
17-01-2020