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

Adding "@" as text in a Label or Text node in a FXML file gives runtime exception, and "@ ..." shows an unexpected text

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 8
    • javafx
    • jdk8.0 b128
      Windows 7, 8, 64 bits

    Description

      While adding Label or Text nodes in a FXML file, a "text" attibute with the content to be displayed must be provided.

      In the following basic sample:

      <?xml version="1.0" encoding="UTF-8"?>

      <?import java.lang.*?>
      <?import java.util.*?>
      <?import javafx.scene.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="textflowtest.TextFlowController">
          <children>
              <Label id="label_with_loadException" text="@" />
              <Label id="label_with_path" text="@Content" />
          </children>
      </AnchorPane>

      if this text is just "@" (first label), a LoadException appears on runtime:

      Caused by: java.lang.RuntimeException: Exception in Application start method
      ...
      Caused by: javafx.fxml.LoadException: Missing relative path
      ...
      at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613)
      at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104)
      at javafx.fxml.FXMLLoader$Element.resolvePrefixedValue(FXMLLoader.java:382)
      at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:357)
      at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:319)
      at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:231)
      at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:761)
      ...

      while in the second label, where the text content starts with "@", there's no exception, but the full path of the fxml file within the executed jar is shown right before the rest of the content.

      Looking at the source code in FXMLLoader, it's clear that '@' is the RELATIVE_PATH_PREFIX character, and typing "\@" instead of "@" fix these problems.

      Clearely, dealing with prefixed values it is intended for the "url" attribute of an Image node or the "value" in an URL, where a proper location must be provided after "@", but in a "text" attribute it may be not necessary. In fact, setting "@" as text of a label on code:

      public void initialize(URL url, ResourceBundle rb) {
              Label l=new Label("@");
      ...
          }

      doesn't give any exception.

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: