ObservableValue Stacktrace

John Hendrikx hjohn at xs4all.nl
Thu Jun 6 01:53:22 PDT 2013


Hm, ok -- it is correct that it doesn't fail, the code runs without any 
problem and everything works as expected.

But, what would be the way to avoid these messages in my log then?  
Something like:

   Bindings.select( Bindings.when(dataProperty().isNull()).then( ??? 
).otherwise(dataProperty()), "castings") );

??

I'd prefer to just turn these warnings off unless there is a really good 
reason to have them (ie, they indicate a logic error or other bug, 
something I can resolve...)

In my case the dataProperty() is often bound to the selection of a 
ListView -- if you have something valid selected, then a Detail Pane is 
filled in with information about the selected item.  When nothing is 
selected (ie, it is null), then the Detail Pane should remain empty... I 
donot want to have to remove/recreate these bindings every time some 
property becomes null.

Also, it seems rather wierd that JavaFX will complain about nulls in the 
first part of the Bindings.select(), but will happily traverse the graph 
(with or without nulls) for the other parts.

Do I have to add an extra level of indirection to get rid off these 
messages, ie something like:

   private final ObjectProperty<Media> data = new SimpleObjectProperty<>();
   public ObjectProperty<Media> dataProperty() { return data; }
   private ObjectProperty<ObjectProperty<Media>> metaDataProperty = new 
SimpleObjectProperty<>(dataProperty());   // extra indirection...
   public ObjectProperty<ObjectProperty<Media>> metaDataProperty() { 
return metaDataProperty ; }

So that I can then do a binding like:

    Bindings.select(metaDataProperty(), "data", "castings");

That seems.. cumbersome :)

--John



On 6/06/2013 09:34, Martin Sladecek wrote:
> JavaFX should not fail in these cases, but doesn't consider that a 
> valid state, so it always prints a warning on the stderr, for the 
> developer to see something went wrong.
>
> Regards,
> -Martin
>
> On 5.6.2013 21:38, John Hendrikx wrote:
>> Hi List,
>>
>> I'm getting some log messages sometimes (see at the end) about 
>> properties being null (whereas I didn't get them before in JavaFX 2.2).
>>
>> Is this intended as an informative message to the developer, 
>> something I should report, or just debug code for the JavaFX team?
>>
>> In this case, the binding is null, and that's fine -- it will be 
>> populated later, but the binding is already in place -- I thought 
>> JavaFX was designed to allow nulls in a chain of bindings and
>> fall back to reasonable defaults for things like Strings, numbers 
>> etc?  Am I doing something wrong?
>>
>> Code:
>> {
>>   private final ObjectProperty<Media> data = new 
>> SimpleObjectProperty<>();
>>   public ObjectProperty<Media> dataProperty() { return data; }
>>
>>   protected final ObjectBinding<ObservableList<Casting>> castings = 
>> Bindings.select(dataProperty(), "castings");
>> }
>>
>> Log:
>>
>> Jun 05, 2013 9:15:55 PM 
>> com.sun.javafx.binding.SelectBinding$SelectBindingHelper 
>> getObservableValue
>> WARNING: Exception while evaluating select-binding [castings]
>> Jun 05, 2013 9:15:55 PM 
>> com.sun.javafx.binding.SelectBinding$SelectBindingHelper 
>> getObservableValue
>> WARNING: Property 'castings' in ObjectProperty [bound, value: null] 
>> is null
>> java.lang.NullPointerException
>>     at 
>> com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:481)
>>     at 
>> com.sun.javafx.binding.SelectBinding$AsObject.computeValue(SelectBinding.java:92)
>>     at javafx.beans.binding.ObjectBinding.get(ObjectBinding.java:152)
>>     at 
>> javafx.beans.binding.ObjectExpression.getValue(ObjectExpression.java:49)
>>     at 
>> com.sun.javafx.binding.ExpressionHelper.addListener(ExpressionHelper.java:53)
>>     at 
>> javafx.beans.binding.ObjectBinding.addListener(ObjectBinding.java:71)
>>     at 
>> javafx.beans.property.ObjectPropertyBase.bind(ObjectPropertyBase.java:170)
>>     at 
>> hs.mediasystem.TitledBlockSample.createCastingsRow(TitledBlockSample.java:114)
>>     at hs.mediasystem.TitledBlockSample.start(TitledBlockSample.java:78)
>>     at 
>> com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:810)
>>     at 
>> com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:260)
>>     at 
>> com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:226)
>>     at 
>> com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:223)
>>     at java.security.AccessController.doPrivileged(Native Method)
>>     at 
>> com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:223)
>>     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$3$1.run(WinApplication.java:101)
>>     at java.lang.Thread.run(Thread.java:724)
>>
>> Regards,
>> --John
>>
>



More information about the openjfx-dev mailing list