JDK-8185709 : CSS class not removed when node not parented
  • Type: Bug
  • Component: javafx
  • Sub-Component: base
  • Affected Version: 8u102,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2017-08-01
  • Updated: 2018-03-27
  • Resolved: 2017-11-30
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.
JDK 10
10Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7, 64 bit

A DESCRIPTION OF THE PROBLEM :
I appeared to have discovered a case in JavaFX where a TextField is rendered using the wrong style class.

The textfield retains its styling using the style class that has been removed. This only appears to happen in the following situation

 * style class removed whilst Node not attached to Scene AND
 * parent `GridPane` has a style-class assigned, even if that class doesn't have content.

Also posted here :https://stackoverflow.com/questions/45440102/javafx-css-class-not-removed-when-node-disconnected

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the example included in the report

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TextField should have red background removed
ACTUAL -
TextField retains red background

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class RenderBug extends Application {

    private static final String ERROR = "error";

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        TextField field = new TextField();
        GridPane grid = new GridPane();
        grid.getStyleClass().add("some-random-class");
        grid.add(field, 0, 0);

        StackPane stack = new StackPane(grid);

        Scene scene = new Scene(stack);
        scene.getStylesheets().add("/foo.css");
        primaryStage.setWidth(300);
        primaryStage.setHeight(300);
        primaryStage.setScene(scene);
        primaryStage.show();

        Timeline line = new Timeline();

        line.getKeyFrames().add(new KeyFrame(Duration.seconds(4), event -> {
            field.getStyleClass().add(ERROR);
        }));
        line.getKeyFrames().add(new KeyFrame(Duration.seconds(5), event -> {
            stack.getChildren().remove(grid);
        }));
        line.getKeyFrames().add(new KeyFrame(Duration.seconds(6), event -> {
            field.getStyleClass().remove(ERROR);
        }));
        line.getKeyFrames().add(new KeyFrame(Duration.seconds(7), event -> {
            stack.getChildren().add(grid);
            System.out.println(field.getStyleClass());
        }));

        line.play();
    }

}


CSS file foo.css

.text-field.error {
    -fx-background-color: red;
}

.some-random-class {
    /** no content required */
}


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

CUSTOMER SUBMITTED WORKAROUND :
Make sure node is attached to scene before making updates to styleClass


Comments
The root cause of this bug and JDK-8183100 is the same. A probable fix has been identified on JDK-8183100.
30-11-2017

Yes. Looks like a duplicate of JDK-8183100. Moving to "Open" state as the test is little different and might help while fixing the issue.
16-08-2017

This seems likely a duplicate of JDK-8183100
02-08-2017

Issue is reproducible and it's a regression introduced in 8u102 (Windows 10) JDK results ========= 8 GA : Pass 8u60 : Pass 8u101 : Pass 8u102 : Fail <------- Regression introduced here 8u121 : Fail 8u141 : Fail 9-ea+180 : Fail ==========
02-08-2017