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

[CSS] ClassCastException in CssStyleHelper calculateValue

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • jfx20
    • jfx11, jfx20, 8
    • javafx
    • b08

    Description

      This issue can be reproduce always by executing TableViewMouseInputTest using the following command:

      ```
      /bin/sh gradlew -PSTUB_RUNTIME=../caches/modular-sdk -PFULL_TEST=true -PUSE_ROBOT=true --no-daemon --info --stacktrace cleanTest :controls:test --tests TableViewMouseInputTest -x :web:test --stacktrace 2>&1 | tee ~/`date +"test-%Y-%m%d-%H%M%S"`.log
      ```

      output:
      TableViewMouseInputTest > test_rt21444_down_row STANDARD_ERROR
          Aug 02, 2022 11:06:00 AM javafx.scene.CssStyleHelper calculateValue
          WARNING: Caught 'java.lang.ClassCastException: class java.lang.String cannot be cast to class javafx.scene.paint.Paint (java.lang.String is in module java.base of loader 'bootstrap'; javafx.scene.paint.Paint is in module javafx.graphics@20-internal of loader 'app')' while converting value for '-fx-background-color' from rule '*.table-row-cell' in stylesheet file:/Users/angorya/Projects/jfx/build/shims/javafx.controls/com/sun/javafx/scene/control/skin/modena/modena.bss
          Aug 02, 2022 11:06:00 AM javafx.scene.CssStyleHelper calculateValue
          WARNING: Caught 'java.lang.ClassCastException: class java.lang.String cannot be cast to class javafx.scene.paint.Paint (java.lang.String is in module java.base of loader 'bootstrap'; javafx.scene.paint.Paint is in module javafx.graphics@20-internal of loader 'app')' while converting value for '-fx-border-color' from rule '*.table-cell' in stylesheet file:/Users/angorya/Projects/jfx/build/shims/javafx.controls/com/sun/javafx/scene/control/skin/modena/modena.bss


      I have seen similar messages when running a javafx application in the field. Also, similar issue was reported in stackoverflow:
      https://stackoverflow.com/questions/27311222/javafx-getting-class-cast-exception-in-css-for-blend-mode

      Also, see JDK-8088468

      ----------------------------------------------------

      Minimal reproducable example:
      ### START ###
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.TableCell;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class CssWarningBug extends Application {

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

          @Override
          public void start(Stage stage) {
              Scene scene = new Scene(new StackPane(buildTableView()));
              stage.setScene(scene);

              stage.show();
          }

          private TableView<String> buildTableView() {
              TableView<String> tableView = new TableView<>();

              TableColumn<String, String> column = new TableColumn<>("column");
              column.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()));
              column.setCellFactory(param -> new ScenePropertyTableCell<>());

              tableView.getColumns().add(column);
              tableView.getItems().addAll("item1", "item2", "item3");

              return tableView;
          }

          private static class ScenePropertyTableCell<S> extends TableCell<S, String> {
              public ScenePropertyTableCell() {
                  sceneProperty().addListener((obs, oldScene, newScene) -> {
                      if (newScene == null || newScene.getRoot().getProperties().containsKey("new.root")) {
                          return;
                      }

                      StackPane newRoot = new StackPane();
                      newRoot.getProperties().put("new.root", true);
                      Parent oldRoot = newScene.getRoot();

                      newScene.setRoot(newRoot);

                      // CLASS CAST EXCEPTION
                      // If this call is before newScene.setRoot(newRoot);, nothing will happen.
                      // Maybe because -fx-table-cell-border-color is not yet parsed because we changed the root?
                      newRoot.getChildren().setAll(oldRoot);
                  });
              }
          }
      }
      ### END ###

      Attachments

        Issue Links

          Activity

            People

              angorya Andy Goryachev
              angorya Andy Goryachev
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: