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

fxmlLoader.load is not setting @FXML attributes for controller

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 8u20
    • 8
    • javafx
    • Java build128
      Windows 8.1
      Intel i5-760
      4GB RAM
      both Eclipse 4.3 and eFXclipse

      I have found this regression in the recent preview builds of Java8. Using build106 there is no problem but using b116 and b128, the bug can be reproduced.

      The bug is related to using the load() method of FXMLLoader object. In certain conditions, the attributes annotated by @FXML are not injected and causing nullPointerException upon access.

      I have found three conditions to reproduce the bug,
      1- Using <fx:root> in the fxml
      2- having the controller in a different package than the instantiating class
      3- using an extension of the controller for instantiation

      I think you will need to have a look at the attached simple example to get the idea, but suffice to say without all three conditions, I was not able to reproduce this bug.

      I didn't have a problem with Javafx2 and build 106 of java8, but when I tried b116, I noticed there was something wrong but I wasn't sure what. When I noticed the issue is still in b128, I decided to investigate it a bit more and report it. When I switch back to b106, the problem is not there and the annotated attributes are properly injected.

      Thanks all

      Run the sample by executing MyMain

            msladecek Martin Sládeček
            hadijfx Hadi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: