Why does this select binding throw a NullPointerException?

This should be pretty simple.  The javadoc for Bindings#selectString says:
Creates a binding used to get a member, such as a.b.c. The value of the binding will be c, or "" if c could not be reached (due to b not having a c property, b being null, or c not being a String etc.).
Running this example:
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.*;
public class SelectBindingExample {
    public static void main(String[] args) {
        ParentModel parentModel = new ParentModel();
        StringBinding bindingA = createBinding(parentModel);
        String nameA = bindingA.get(); // NPE while evaluating
        System.out.println("Bound value is " + (nameA != null ? nameA : "null") + ".");
        parentModel.setChildModel(new ChildModel());
        StringBinding bindingB = createBinding(parentModel);
        String nameB = bindingB.get();
        System.out.println("Bound value is " + (nameB != null ? nameB : "null") + ".");
    private static StringBinding createBinding(ParentModel parentModel) {
        return Bindings.selectString(parentModel.childModelProperty(), "name");
    public static class ParentModel {
        private final ObjectProperty<ChildModel> childModel = new SimpleObjectProperty<>();
        public final ReadOnlyObjectProperty<ChildModel> childModelProperty() {return childModel;}
        public final ChildModel getChildModel() {return childModel.get();}
        public final void setChildModel(ChildModel childModel) {this.childModel.set(childModel);}
    public static class ChildModel {
        private final StringProperty name = new SimpleStringProperty("Child Model Name");
        public final ReadOnlyStringProperty nameProperty() {return name;}
        public final String getName() {return name.get();}
        protected final void setName(String name) {this.name.set(name);}
..causes a NPE while evaluating the binding:
WARNING: Exception while evaluating select-binding [name]
Jan 24, 2014 7:10:57 AM com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
INFO: Property 'name' in ReadOnlyObjectProperty [bean: SelectBindingExample$ParentModel@4437c4, name: childModel, 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 SelectBindingExample.main(SelectBindingExample.java:9)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
What's going wrong here?  I've updated the example to work with the Bindings#selectString method from Java 7 and things work as expected.  Is this a bug?
Slight modification to the example so it works with Java 7.

An additional thought, though.
This suggests (implies, I think) that Bindings.selectString(...) is using try-catch structures to process the logic of stepping through the properties and evaluating the result. In pseudocode, something like
public static StringBinding selectString(ObservableValue<?> root, String... steps) {
   try {
    ObservableValue<?> ov = root ;
    for (String step : steps) {
       ov = findObservableValue(ov, step);
    return (String) ov.getValue();
  } catch (NullPointerException | ClassCastException exc) {
   // display horrible warning
   return "" ;
Apart from the unnecessary warning (because the state that's being warned about is supported, according to the spec), this is a very inefficient implementation, and it wouldn't be too hard, for example, to come up with scenarios where this made table sorting of the order of 100 times slower than it should be. (See this for a similar example, which is now fixed.) It is probably worth verifying this, and filing a JIRA if true.

Similar Messages

  • Why does this select statement fail.....

    declare
    t_name varchar2(100):='america';
    begin
    execute immediate '
    select * from'|| t_name;
    end;

    Because it looks like you need to add a space after 'from' and add an INTO CLAUSE?
    introduction to bulk pl/sql enhancements in 9i

  • HT5007 Why does this app stop at about 10 seconds into a selected trailer then resume on it's own?

    Why does this app stop and resume?

    I believe the OP is asking about the Apple iTunes Movies Trailer app, so it is an Apple app.
    I think maybe the video playback catches up with the download and until the download resumes, the video is stopping. Just a guess at this point.

  • Lately when I sync certain albums to my iPhone, the tracks are duplicated one behind the other so that I have to listen to each song twice. Why does this happen and how can it be fixed?

    Lately when I sync certain albums to my iPhone, the tracks are duplicated one behind the other so that I have to listen to each song twice. Why does this happen and how can it be fixed?

    Very strange behavior.  Don't entirely give up on the "Manually Added Items" category ... I have seen things magically appear there even after I've checked and seen nothing there.  I think things got real quirky when Apple released iCloud ... I don't remember extra copies of purchases lingering on my iPhone once transferred to my library before that.  Sure, if I bought an album directly to my iPhone it would stay on there even after I sync to my library, but if I deleted the album from the iPhone it stayed deleted.  Now it seems that there are some phantom copies that come and go with no explanation.
    jcburbank wrote:
    I've tried deleting the album from both the phone and from iTunes and then redownloading them to both and the same problem occurs.
    If you're re-downloading an album to iTunes and your iPhone, that may perpetuate the problem.  What happens if you completely delete every copy of the album, then just download to your iTunes library and then sync the album to your iPhone from your library?  That should put only one copy on your iPhone.
    A few other things to try:
    1- Completely sign out of your Apple account on your iPhone, then re-sync to iTunes, then sign into your account on your iPhone again.  Maybe throw in a Reset or at least a power OFF/ON somewhere in the middle.
    2- Go to Settings/ General/ Usage, then select Music and when you see All Music, swipe your finger across it and tap the Delete button.  Before doing anything else, Reset your iPhone.  This does not actually delete your music, but seems to clear up some cobwebs left behind (people use this technique to reduce "Other" that swells up over time).

  • While trying to instal Mountain Lion OS on my macbook pro, I got the error message that my HD was damaged and it reverted to my Lion OS. Why does this happen? I bought the OS online through the app store

    While trying to instal Mountain Lion OS on my macbook pro, I got the error message that my HD was damaged and it reverted to my Lion OS. Why does this happen? I bought the OS online through the app store.

    The Mountain Lion installer looks at your internal drive to make certain that it's error-free before continuing installation. You should have an application named "Install OS X Mountain Lion.app" in your Applications folder now so you shouldn't have to download it again. Do this...
    Boot to your Lion recovery partition by holding down both the Command and the R keys while booting. Open Disk Utility from the Recovery partition and select your hard drive (usually named "Macintosh HD" unless you've renamed it) and click on Verify Disk. If you come up with any errors, click on Repair Disk. At the end of the cycle you will get a message that the disk was successfully repaired or a message that the hard drive could not be repaired.
    If you're able to repair the disk, just reboot as normal and open the "Install OS X Mountain Lion.app" and the installation will proceed. If Disk Utility was unable to repair the disk, you need to get to your local Apple Store as soon as possible so that they can see if the disk is salvageable or beyond repair.
    Good luck,
    Clinton

  • My 3rd gen apple tv will loose all sound output once in a while... why does this happen?

    my 3rd gen apple tv will loose all sound output once in a while... why does this happen? when i come home from work and turn on apple tv there is no sound. not even the sound effect when you move your selection cursor around the home screen. ive called into apple support and they were really helpful. the problem was at the time that i needed to sign out of apple and back in after i update the software. this is recurring now off and on for 2 weeks. does anyone have any ideas?

    Hi,
    Beacon Interval - 400
    Threshold - 2346
    RTS - 2347
    DTIM interval - 1
    CTS protection mode - Disabled
    Basic rate - Default
    Transmittion rate - Auto(Negotiating)
    So the other client must have that settings on network adapter Control Panel->Network Connections->configure->Link Speed Duplex - Auto(Default settings).
    I hope that to be helpfull for you,if not please let me know.
    Thanks!!!!!!
    George
    Thanks
    Kind Regards
    ing.George Gochev
    DSL and Telecommunications Engineer

  • I cannot send an email from my iPad 2? No problem receiving, why does this happen? Have tried the suggestions for setting up email and after doing the sync mail through iTunes receiving worked great but still cannot send? Any help would be great

    I cannot send an email from my iPad 2? No problem receiving, why does this happen? Have tried the suggestions for setting up email and after doing the sync mail through iTunes receiving worked great but still cannot send? Any help would be great!

    The fact that you can receive means you have a valid e mail address, and have established the connection to the incoming server, so all of that works.  Since the send does not work, that means your outgoing server is rejecting whatever settings you used formthe outgoing set up.  Try them again. 
    Google your particular isp, and ipad and many times you will find the exact settings needed for your isp.  Or tell us here, and soneone else may be on the same isp.  Some mail services need you to change a port, or have a unique name for the outgoing server.  
    Kep trying.

  • HT201209 iTunes will not use the redeemed gift cards on my account, I have a $30 credit and when I try to purchase a song it goes right to my credit card on file. Why does this keep happening

    iTunes will not use the redeemed gift cards on my account, I have a $30 credit and when I try to purchase a song it goes right to my credit card on file. Why does this keep happening???

    Any time you've changed anything in your billing, it does this once to very things.

  • TS4062 when i sync my iphone a large portion of my music does not download but rather stays in the cloud. then i must download it from the cloud. why does this happen and how can i stop it from happening

    every time that i sync my iphone with a cord to my imac some large portion of my music is placed in the cloud so that i must down load it from the cloud. this includes music that i have purchased on itunes and other music. it seems random.
    why does this happen? is it a setting? i want to stop it. and music that w

    It was gift back in September. You can follow the instructions in the link below to remove them:
    Remove iTunes gift album "Songs of Innocence" from your iTunes music library and purchases - Apple Support

  • My iphone is suddenly populated by random songs I've downloaded in the past. Why does this happen, and what are apple doing about fixing this?

    Why does this happen?
    What do other people do? (I can't go to sleep knowing there's a rogue album or song in my music. It's 2am now)
    What do we tell apple so that they actually fix it. None of us want to pay £25 to have our own music.

    I am on the monthly payment plan because nobody at BT has told me there is any alternative!
    Each year there I have a long, in-depth conversation with the person who sets up the contract for the next year but the gist of the thing is 'I'm  not going to be paying more than [x amount] per month, am I? Because I can't afford any more'' and each year the person says that no, in fact I should be paying less... and then without notice and even with the bill saying 'We will continue to take....' a totally different - and higher - sum disappears from my bank account.
    Then I go through the painful process of writing to complain about this, get some sort of sum refunded and then the payments go through at the level they should, with me paying any additional (usually small) amounts for usage over the allowance. Until contract end when we start all over again...
    Even if the amount they seem to randomly decide on is based on some sort of forecast, this should not be happening as I am doing what they instruct me to do on the bill to keep my payments the same.
    So something is going wrong, on many levels.
    At no point have I been offered the sort of 'monthly billing' described here; maybe there is some reason I am not allowed it. Unfortunately 'whole bill' direct debit payment is beyond me. I really need to know what I will be paying each month and I need BT to correctly take that amount, as agreed, each month, from the get-go.
    It shouldn't be that hard really! Does anyone from BT read these forums? Can somebody take this on and finally get this straight, please?

  • Why does this message keep appearing when i try to instal windows 7 through bootcamp? - "something went wrong and the USB cannot be configured for the installation"

    Why does this message keep appearing when Itry to instal windows 7 through bootcamp? - "Your bootable USB drive could not be created. An error occurred while copying the Windows installation files."

    Found a solution!
    Follow the extended version of these directions here:
    https://discussions.apple.com/docs/DOC-3581
    Worked like a charm!

  • HT2500 I sometimes get e-mails where the sender sends me several PDF's attachments. These attachments appear already opened on the e-mail unlike most PDF's which I open by clicking on the PDF icon. Why does this happen?

    I sometimes get e-mails with pdf attachments. However instead of opening a PDF icon the body of the e-mail message has the PDF's already opened. Why does this happen? Is there anything I can change on my mac book pro to make these PDF's come thru with their individual icons which can then be opened.

    This is a long-standing design flaw in Apple Mail.
    Prior to Mavericks, this command in Terminal would stop the annoying behavior:
    defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
    This Terminal command stopped working in Mail 7.1 under Mavericks. I have reported this to Apple as both a feature request and a bug. You should too.
    http://www.apple.com/feeback

  • HT2470 Why does this not explain how to change the sort order?

    Why does this (i.e. support at Apple.com) not explain how to change the sort order? I can "arrange" by Date Modified for example but it won't let me switch to use most recent dates first. Also, what is Apple-speak for arrange versus sort anyway? It seems I used to be able to click on a column heading in finder and get a drop down arrow allowing me to change the sort sequence.

    Arrange roughly translates to "group the items in the folder." Sort is how each group is ordered. If you have arrange set to none, you can sort by anything. However, there is no way in the Arrange/Sort menu to choose the direction. The only way to do that is in the List View, and you must have Arrangement set to None.
    I've submitted an Enhancement Request to allow choosing sort direction from the Arrange/Sort menu, but I haven't ever gotten a response, which is good and bad. Good because they will often respond that they have considered it and don't plan on implementing. Bad in that they've haven't implemented it.

  • Why does my ipad keep throwing me out of games and apps?

    Why does my ipad keep throwing me out of games and apps?

    Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • HP Photosmart C8180 Printer! WHY does this keep happening every day??

    I have only had this for 3 months and it already has problems.
    It keeps telling me its out of paper when it is not.
    i always have at least 20 sheets in there!
    You can hear the rollers going but it can't pick up the paper and I only use high quality A4 paper in there.
    i then have to pull the tray out and push it back in, and yes i have the paper inserted in there correctly
    also, sometimes when i get this "out of paper" message, i ignore it and just press OK and it works fine 
    why does this keep happening?
    this is disgusting coming from a Quality brand like HP
    think its time to go to BBC Watchdog! 
    A printer is an item meant to print. 
    It is generally helpful if a printer recognizes such out-of-the-ordinary, eccentric, unheard-of media such as...oh, I dunno, 8.5 x 11-inch PAPER?????
    It claims repeatedly to have run out of paper. No paper. No paper. Insert paper into paper tray. Now, granted, the minimalist quality of the paper tray--it holds 20 pages, roughly--might convince you that I had indeed used up all my paper; this is not the case. 18 of the 20 sheets are still there. So I readjust that paper, close the tray. It starts to pull in a piece of paper, and then there is the giant crunchy noise of a paper jam in progress. And forget about “easy access” for removing them, either.
    In the months I have had this printer, I don’t believe it has EVER allowed me to print five pages consecutively without some sort of problem.  To me, this is known as an EPIC FAIL. 
    Message Edited by Waynester on 04-16-2009 04:09 PM

    So how is the printer set up?  Is it wireless or USB?  If USB you will need a cable, purchased seperately.  It is a standard A/B USB cable widely available inexpensively.  (The $1 cables form the dollar store work fine....
    Running the diagnostics at http://www.hp.com/go/tools may help resolve the issue.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

Maybe you are looking for

  • Help needed ! Message sending failure in Nokia N73

    HI I am using nokia n73 for almost 2 years, From last one week i am unable to send messages, as soon as i send a message, in the outbox it changes to resend and when i resend it and after four times it moves to failed state. I have tried the sim in d

  • Download file format(different length data on one column)

    Hi all, i am just writing a report to download the delivery data to a file.the file have 3 columns.the length of the column data in every row varies. let my file structure is like first line of my file contains, delivery no(22),delivery date(8),deliv

  • Service Application Remains in Stopping State Between Reboots

    These SharePoint service applications are a real pain! I'm trying to stop a service application, but it remains in a hung "stopping" state (even between reboots!). I've also tried to delete the service application from powershell using "Remove-SPServ

  • NUMC characteristic with a range + offset restriction

    Wondering if someone knows a way to fix this: I built a report that has a characteristic that contains the numerical difference between two dates.  then I setup columns that filter a range 0-5, 6-10, 11-15, 16-20.  Up to now everything works fine. No

  • Link to Download Vers. 7 is Broken

    Hi, The link to downloading CF Server Vers. 7 Developer Edition is broken. It links only to the Vers. 8 download. http://www.adobe.com/products/coldfusion/coldfusion7/ I need version 7 on my development PC, to replicate our CF Version 7 that we have