Possible NullPointerException in notifications

Issue #811 resolved
Arthur Leitner
created an issue

Showing a notification causes a NullPointerException when there is no owner window. The problem is in of org.controlsfx.control.Notifications in the private method show(Window owner, final Notifications notification). On line 344 the method getScene() is called from the Window ownerWindow, although this reference may be null.

The relevant code snippet:

private void show(Window owner, final Notifications notification) {
            // Stylesheets which are added to the scene of a popup aren't 
            // considered for styling. For this reason, we need to find the next 
            // window in the hierarchy which isn't a popup.  
            Window ownerWindow = owner;
            while (ownerWindow instanceof PopupWindow) {
                ownerWindow = ((PopupWindow) ownerWindow).getOwnerWindow();
            // need to install our CSS
            Scene ownerScene = ownerWindow.getScene();  // NPE happens here !!!!
           // ...

I have found this problem in version 9.0.0. It may be also exist in the branch for Java 8.

Comments (10)

  1. Abhinay Agarwal

    Can you post a SSCCE which reproduces the issue?

    It is strange that this issue exists since the private show() is called by the public show(), which has a null check in place for owner window.

    public void show(Notifications notification) {
        Window window;
        if (notification.owner == null) {
            window = Utils.getWindow(null);
        } else {
            window = notification.owner;
        show(window, notification);
  2. Arthur Leitner reporter

    Sorry, but the null check does not really provide perfect safety, because Utils.getWindow(null) may actually return null. In our system this NPE happens occasionally, when a notification in the onClosing event is created and shown. Providing a SSCCE for this occasional event may be hard, since I have a hunch that a race condition may be involved. Therefore I hope you can follow my argument and accept this answer instead. If not, I will provide a SSCCE of course.

  3. Log in to comment