Search code examples
scalajavafx-8scala-2.12

annotation information lost in scala 2.12 trait


Just updated a scala 2.11 + JavaFX project to 2.12.0-RC1, the code use java @FXML annotation intensively, e.g.

trait MainController {
  @FXML def onRun(event: ActionEvent) {
    val script = currentEngine.executeScript("editor.getValue()").toString
    runScript(script)
  }
}

<MenuItem mnemonicParsing="false" onAction="#onRun" text="Run">
   <accelerator>
        <KeyCodeCombination alt="UP" code="R" control="UP" meta="UP" shift="UP" shortcut="DOWN"/>
   </accelerator>
</MenuItem>

At runtime it throws error while executing FXMLLoader.load:

javafx.fxml.LoadException: Error resolving onAction='#onRun', either the event handler is not in the Namespace or there is an error in the script.

Seems that the @FXML annotation information has been lost during compilation. I have heard that in 2.12 all traits are compiled to interfaces, but how does this change cause the problem? Is there any workaround?


Solution

  • Though the reason remains unknown, this problem has been solved in scala-2.12.0-RC2. Thank you, the Scala team.