RFR: JDK-8298104: NPE on synchronizeSceneNodes()

John Hendrikx jhendrikx at openjdk.org
Thu May 4 10:49:26 UTC 2023


On Wed, 3 May 2023 11:46:50 GMT, buedi <duke at openjdk.org> wrote:

> A null pointer exception occurs on the ScenePulseListener when iterating through the dirty node list.
> A null check is needed on the node before calling node.getScene().
> 
> The error occurs occasionally and causes the application to crash.

Hi @buedi, I've taken a look at this, but would like to know the root cause. I get the impression that this happens a lot for you, could you share when this happens so I can reproduce this as well?

You could also try this code and report back if you get any of the exceptions I added:

        private void synchronizeSceneNodes() {
            Toolkit.getToolkit().checkFxUserThread();

            Scene.inSynchronizer = true;

            // if dirtyNodes is null then that means this Scene has not yet been
            // synchronized, and so we will simply synchronize every node in the
            // scene and then create the dirty nodes array list
            if (Scene.this.dirtyNodes == null) {
                // must do this recursively
                syncAll(getRoot());
                dirtyNodes = new Node[MIN_DIRTY_CAPACITY];

            } else {
                if (peer == null) {
                    throw new IllegalStateException("peer shouldn't be null here: " + dirtyNodesSize);
                }

                // This is not the first time this scene has been synchronized,
                // so we will only synchronize those nodes that need it
                for (int i = 0 ; i < dirtyNodesSize; ++i) {
                    try {
                        Node node = dirtyNodes[i];
                        dirtyNodes[i] = null;
                        if (node.getScene() == Scene.this) {
                            node.syncPeer();
                        }
                    }
                    catch (Throwable e) {
                        throw new IllegalStateException("exception will break dirtyNodes!", e);
                    }
                }
                dirtyNodesSize = 0;
            }

            if (!Scene.inSynchronizer) {
                throw new IllegalStateException("Synchronizer flag was reset, reentrant call?");
            }

            Scene.inSynchronizer = false;
        }

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1123#issuecomment-1534538130


More information about the openjfx-dev mailing list