• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointer after application is idle for a few hours

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We've got an unhandled exception handler set up in our app, and it is catching a nullpointerexception after our JavaFX app sits idle for a few hours. Anybody else seen this?
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please supply more details so we can work out what is happening.
 
Troy Cowan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're using JDK/JavaFX 8. In our main function we call Thread.setDefaultUncaughtExceptionHandler and specify method that pops up a dialog with an error message and the stack trace of the exception.

We launch our application and just leave it up and running but don't interact with it for many hours. Not sure if there is an exact threshold. When we go back to the PC running the application, there is a dialog from our uncaught exception handler notifying us of a null pointer exception. The stack trace only shows lines of code from javafx or other com.sun packages, as though the problem had nothing to do with our code but is internal to javaFX (pasted below). Not sure at all how to attack this problem.

java.lang.NullPointerException
at com.sun.javafx.text.PrismTextLayout.shape(PrismTextLayout.java:869)
at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1064)
at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223)
at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246)
at javafx.scene.text.Text.getLogicalBounds(Text.java:358)
at javafx.scene.text.Text.impl_computeGeomBounds(Text.java:1168)
at javafx.scene.Node.updateGeomBounds(Node.java:3579)
at javafx.scene.Node.getGeomBounds(Node.java:3532)
at javafx.scene.Node.getLocalBounds(Node.java:3480)
at javafx.scene.Node$MiscProperties$2.computeBounds(Node.java:6474)
at javafx.scene.Node$LazyBoundsProperty.get(Node.java:9308)
at javafx.scene.Node$LazyBoundsProperty.get(Node.java:9278)
at javafx.scene.Node.getBoundsInLocal(Node.java:3158)
at com.sun.javafx.scene.control.skin.TextAreaSkin$ContentView.layoutChildren(TextAreaSkin.java:207)
at javafx.scene.Parent.layout(Parent.java:1087)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run$$$capture(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the stack trace always the same, or does it differ sometimes?

What is the exact version of JavaFX you are using?
(so that somebody could analyze the stack trace against the JavaFX source code to see what source the line numbers correspond to).

Are you doing any work at all off of the JavaFX thread, and modifying or reading anything to do with the scene graph from the other thread?
(which can cause race conditions which can lead to unexpected exceptions occurring).
See the stack overflow question linked below to understand what kind of issues may arise from doing things like this and how to prevent them:
 https://stackoverflow.com/questions/38770112/javafx-changing-text-area-in-javafx-concurrent-task
 
Troy Cowan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My javafx.properites file shows:

Javafx.runtime.version=8.0.112
Javafx.runtime.build=b15

Not sure if the stack trace is always the same; I've only copied off the one. I will pay attention next time.

Not sure what you mean by "scene graph". We know not to try and update GUI controls from threads that are not the JavaFX thread. We usually get an exception right away when we violate this. Is there a way where we can do something wrong in this area and not see it right away?
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Not sure what you mean by "scene graph".

See the following articles to see what the scene graph is:

* https://docs.oracle.com/javafx/2/architecture/jfxpub-architecture.htm#A1106328
* https://docs.oracle.com/javafx/2/scenegraph/jfxpub-scenegraph.htm

Basically, if a node is in an active scene graph, i.e. attached to a displayed window or a scene you try to snapshot, then you can't set or query any of the properties of any the node which is attached to the scene graph, or change the structure of the scene graph by adding or removing nodes.

> Is there a way where we can do something wrong in this area and not see it right away?

Yes, when you modify or query a value off of the JavaFX application thread, then there is no guarantee that an exception will be thrown which you can handle, indeed it may just break the app in an unpredictable way due to a phenomenon known as a race condition:
 https://en.wikipedia.org/wiki/Race_condition#Example
Sometimes the JavaFX system is sophisticated enough to detect some sources of potential race conditions and raise exceptions before they occur, other times it is not, and some unexpected error just occurs.

I couldn't tell you if you have a race condition in your code, but it is one possible cause of exceptions like the one you logged.  In my experience, unless there is a coding error in the underlying JavaFX framework, a race condition is the most likely cause of issues similar to what you are observing.

One reason why I asked if the stack trace is always the same, is that sometimes when you have a race condition, an error can manifest itself in different ways, seeming somewhat random and the exact location where the exception occurs can change depending upon when data was concurrently modified or viewed by different threads.

> Javafx.runtime.version=8.0.112

If the problem is actually an internal error in JavaFX, and not in your code, then you could try upgrading to a later version of JavaFX and seeing if it fixes the issue (because a bug fix which occurred sometime in the last few years might have fixed the cause of the issue).
 
Troy Cowan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the explanations.

you could try upgrading to a later version of JavaFX and seeing if it fixes the issue



Is it possible to upgrade JavaFX without upgrading the SDK, or are they linked at that level? I'm assuming were talking about upgrading from 8.0.112 to 8.0.<latest>
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Is it possible to upgrade JavaFX without upgrading the SDK, or are they linked at that level?

For Java 8 and 9 the JavaFX system is part of the JRE, so, no, for those versions, you can't upgrade JavaFX without also upgrading the JRE.
For later versions based upon the versions distributed at https://openjfx.io the JavaFX system is distributed as a distinct set of libraries and modules from the JRE, so they are not as tightly entwined.  Whether for openjfx it is possible to upgrade JavaFX independent of the JRE (and vice versa), I don't know, but I wouldn't be surprised if that is possible.

> I'm assuming were talking about upgrading from 8.0.112 to 8.0.<latest>

No Java 8 is quite old now and (as far as I can tell, only on long term support, so that it gets fixes for major security issues, but not other bug fixes).
I was talking about trying the most recent version of openjfx (openjfx 12 on openjdk JRE 12). If any bug fixes for your issue were done over the years (assuming it is a bug in JavaFX that needed to be fixed, which it might not be), then the fixes should show up in the latest version of the code.
 
Troy Cowan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Upgrading the JRE at this point in the project is a no go. Looks like our best bet is to scour our code looking for places where we are interacting with nodes in the scene graph on threads other than the JavaFX thread.

Thanks for all your help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic