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

[javaFX8] Bindings created with Bindings.selectXXX() cause NPE upon evaluation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8
    • javafx
    • Windows 7 64bit, JDK 8 64bit, JavaFX 8 64bit, Netbeans 8

      In JDK 8 + JavaFX 8, when creating bindings using Bindings.selecXXX() methods, upon evaluating the value returned by calling the getter of the object, a NullPointerException is generated and printed on the error output. The NPE generated does not prevent the code from being executed.

      No NPE is printed when using JDK 7 + JavaFX 2.x.

      See the following code:

      final Pane pane = new Pane();
      final BooleanBinding fullsceenProperty = Bindings.selectBoolean(pane.sceneProperty(), "window", "fullscreen");
      final DoubleBinding widthProperty = Bindings.selectDouble(pane.sceneProperty(), "window", "width");
      final StringBinding titleProperty = Bindings.selectString(pane.sceneProperty(), "window", "title");

      As is there is no error.
      Now we evaluate the value of the bindings by calling the getValue() method on each:

      System.out.printf("visible: %b", fullsceenProperty.getValue()).println();
      System.out.printf("width: %f", widthProperty.getValue()).println();
      System.out.printf("title: %s", titleProperty.getValue()).println();

      We get the correct output in both JDK7 and JDK8:

      visible: false
      width: 0.000000
      title: null

      From the Bindings.selectXXX() methods documentations, these values are correct as the scene property of the pane object is currently set to Null (the pane has not been attached to a scene yet at this point).

      However, in JDK8 we also have the following non-critical non-execution-stopping NullPointerException that are printed on the error output:

      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      WARNING: Exception while evaluating select-binding [window, fullscreen]
      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      INFO: Property 'window' in ReadOnlyObjectProperty [bean: Pane@6378623f, name: scene, value: null] is null
      java.lang.NullPointerException
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:481)
      at com.sun.javafx.binding.SelectBinding$AsBoolean.computeValue(SelectBinding.java:139)
      at javafx.beans.binding.BooleanBinding.get(BooleanBinding.java:157)
      at javafx.beans.binding.BooleanExpression.getValue(BooleanExpression.java:56)
      at test.Main.start(Main.java:28)
      at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
      at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
      at java.lang.Thread.run(Thread.java:744)

      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      WARNING: Exception while evaluating select-binding [window, width]
      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      INFO: Property 'window' in ReadOnlyObjectProperty [bean: Pane@6378623f, name: scene, value: null] is null
      java.lang.NullPointerException
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:481)
      at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:190)
      at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:203)
      at javafx.beans.binding.DoubleExpression.getValue(DoubleExpression.java:70)
      at test.Main.start(Main.java:29)
      at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
      at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
      at java.lang.Thread.run(Thread.java:744)

      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      WARNING: Exception while evaluating select-binding [window, title]
      Mar 21, 2014 2:44:10 PM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
      INFO: Property 'window' in ReadOnlyObjectProperty [bean: Pane@6378623f, name: scene, value: null] is null
      java.lang.NullPointerException
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:481)
      at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:394)
      at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
      at javafx.beans.binding.StringBinding.get(StringBinding.java:61)
      at javafx.beans.binding.StringExpression.getValue(StringExpression.java:51)
      at test.Main.start(Main.java:30)
      at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
      at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
      at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
      at java.lang.Thread.run(Thread.java:744)

      These NPE should not appear to the programmer or the documentation of the various Bindings.selectXXX() methods should be expanded to describe this behavior.

            msladecek Martin Sládeček
            fbouyajfx Fabrice Bouyé (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: