Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8183100

Styles not applied reliably after Java 8u92

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
    • CPU:
      x86
    • OS:
      generic

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_131"
        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
        Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

        Also happens in 8u111, 8u152 and 9+175. The bug did not affect Java 8u92.

        ADDITIONAL OS VERSION INFORMATION :
        Darwin Mac 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

        However, we have also seen this bug on Windows and Linux.

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        The example code uses Node#setStyle. In our actual application we use Application.setUserAgentStylesheet, but both ways of styling nodes are affected.

        A DESCRIPTION OF THE PROBLEM :
        Our JavaFX application uses a custom setup similar to a TabPane where we replace a container in our scene depending on the selected tab. The attached example resembles this structure.

        However, if we add styled nodes to a container that we've just removed from the scene, then later add this container again, the styles of these added nodes are not applied consistently.

        This is not a multithreading issue, and it always affects the same nodes. It's a pretty deterministic bug.

        This regression might be related to the optimisation that addressed issue 8151756:

        https://bugs.openjdk.java.net/browse/JDK-8151756

        (Note the comment that has trouble with user-agent stylesheets in Java 8u>92)

        REGRESSION. Last worked in version 8u102

        ADDITIONAL REGRESSION INFORMATION:
        8u92 works - we haven't tested versions between 92 (works) and 111 (broken)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached program.

        1. Click "Add and select new tab". This will open a tab with a yellow background.
        2. Click "Add and select new tab" again. This will create a second tab, but will ALSO replace the contents of the first tab (now in the background) with a fresh yellow pane.
        3. Click the first "Tab" in the tab bar to return to the first tab. The yellow background colour was not applied while the tab was in the background, and going back and forth between tabs does not fix this.
        4. Every time a new tab is added, all existing tabs break.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Before opening any tabs, the bottom container should be _red_. After creating and switching between tabs, the bottom half of the screen should always be _yellow_.
        ACTUAL -
        The bottom half of the screen is _yellow_ when opening a fresh tab, but _fuchsia_ when returning to tab that was modified while in the background.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.*;
        import javafx.application.*;
        import javafx.scene.Scene;
        import javafx.scene.control.*;
        import javafx.scene.layout.*;
        import javafx.stage.Stage;

        public class CSSBugDemo extends Application {
          static List<TabContents> TAB_CONTENTS = new ArrayList<>();

          static class TabContents extends StackPane {
            public TabContents() {
              // It is important that this node has some styling, either via setStyle() or getStyleClass().add().
              // It doesn't matter whether this is a valid style or just "-invalid-attribute: 0;"...
              setStyle("-fx-background-color: fuchsia");

              Platform.runLater(() -> {
                TAB_CONTENTS.add(this);
                TAB_CONTENTS.forEach(TabContents::fillWithFreshYellowPane);
              });
            }

            void fillWithFreshYellowPane() {
              Pane yellowPane = new Pane();
              yellowPane.setStyle("-fx-background-color: yellow");
              getChildren().setAll(yellowPane);
            }
          }
          
          @Override
          public void start(Stage primaryStage) {
            // Top half of the app: Horizontal navigation bar above the application.
            Button reapplyCSSButton = new Button("Reapply CSS");
            Button addTabButton = new Button("Add and select new tab");
            HBox tabBar = new HBox(reapplyCSSButton, addTabButton);

            // Bottom half of the app: The actual tab contents.
            StackPane container = new StackPane();
            // It is important that this node has some styling, either via setStyle() or getStyleClass().add().
            container.setStyle("-fx-background-color: red");
            VBox.setVgrow(container, Priority.ALWAYS);

            VBox root = new VBox(tabBar, container);

            // This needs to be removed for compilation with JDK 9.
            reapplyCSSButton.setOnAction(unused -> root.impl_reapplyCSS());

            ToggleGroup group = new ToggleGroup();

            addTabButton.setOnAction(unused -> {
              ToggleButton toggle = new ToggleButton("Tab");
              toggle.setToggleGroup(group);
              toggle.setSelected(true);
              tabBar.getChildren().add(toggle);

              TabContents contents = new TabContents();
              // Immediately select the new tab...
              container.getChildren().setAll(contents);
              // ...and select it again when clicking the toggle.
              toggle.setOnAction(actionEvent -> container.getChildren().setAll(contents));
            });

            primaryStage.setScene(new Scene(root, 500, 500));
            primaryStage.show();
          }

          public static void main(String[] args) { launch(args); }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Calling impl_reapplyCSS() fixes the bug by applying CSS again. This workaround is not available in JDK 9.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  aghaisas Ajit Ghaisas
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  8 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: