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

ObservableList<String> children property cannot be assigned correctly.

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows11 Pro 23H2
      jdk: graalvm 17.0.9
      javafx: 17.0.11

      A DESCRIPTION OF THE PROBLEM :
      In the FXML file, when creating the `MyPoint` object in the define block, if the parameterized constructor of the `MyPoint` class contains the `NamedArg` annotation, the `ObservableList<String> children property` under `MyPoint` cannot be assigned correctly. The class contains a `public ObservableList<String> getChildren()` method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Start the main method of the FxmlTest class

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Print result:
      items:[B, A]
      ACTUAL -
      Print result:
      items:[B]

      ---------- BEGIN SOURCE ----------
      ```java
      public class MyPoint{

          private final ObservableList<String> children = FXCollections.observableArrayList();

          public ObservableList<String> getChildren() {
              return children;
          }

          private int x;

          private int y;

          public int getX() {
              return x;
          }

          public void setX(int x) {
              this.x = x;
          }

          public int getY() {
              return y;
          }

          public void setY(int y) {
              this.y = y;
          }

          public MyPoint(@NamedArg("x") int x, @NamedArg("y") int y) {
              this.x = x;
              this.y = y;
          }

      }
      ```

      FxmlTest.fxml
      ```xml
      <AnchorPane xmlns="http://javafx.com/javafx"
                  xmlns:fx="http://javafx.com/fxml"
                  fx:controller="club.xiaojiawei.test.FxmlTest"
                  prefHeight="400.0" prefWidth="400">
          <fx:define>
              <MyPoint fx:id="point">
                  <children>
                      <String fx:value="B"/>
                      <String fx:value="A"/>
                  </children>
              </MyPoint>
          </fx:define>
      </AnchorPane>
      ```
      Application
      ```java
      public class FxmlTest extends Application {

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

          @FXML
          private MyPoint point;
          @FXML void initialize(){
              System.out.println("items:" + point.getChildren());
          }

          @Override
          public void start(Stage primaryStage) throws IOException {
              FXMLLoader loader = new FXMLLoader();
              Parent root = loader.load(getClass().getResourceAsStream("FxmlTest.fxml"));
              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }
      ```
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Replace 'public ObservableList<String> getChildren()' with 'public List<String> getChildren()'

      FREQUENCY : always


            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: