JavaFX is great for building user interfaces. There is however one large annoyance that is probably considered a feature. JavaFX swallows
NullPointerExceptions, among others.
NPE’s are meant to signal development errors. In other words, if you see an NPE, you can call your developer and tell him he screwed up. Some developers even need them to be reminded of the pieces of an application they were working on.
The fact that JavaFX swallows many exceptions, makes it hard to find out if you made a programming booboo or not. As an example, today my colleague was working on a zooming/scaling algorithm. The calculations were all correct, since we could check them by the many
FX.println statements we added to the algorithm:
----------------------- Scale factor: 2.5 sceneX: 254.0 sceneY: 158.0 ... etc topLeft X: 0.0 topLeft Y: 0.0 -----------------------
It all seemed a-okay, with one exception: the
topLeft X and Y remained at 0.0, even though the following statements were included in the algorithm:
topLeft.x = x; topLeft.y = y;
Now, after some more
println statements and some name-calling, we found that the
topLeft object was
null. It simply had not been initialized. Normally, in Java, this would have become apparent the very first time we ran the application, but now it required fifteen minutes of wonder and debugging.
If someone can explain the use of this feature to me, I invite them to leave a comment. On the other hand, I would like to ask the JavaFX people to at least give me a way to turn this off, so I can tell my colleague he made a booboo 🙂