Skip to content

Dialog parent can be a closed window #8667

@rkeen-siemens

Description

@rkeen-siemens

Apache NetBeans version

Apache NetBeans 26

What happened

Utilities.findDialogParent can return a non-visible component which is effectively equivalent to null and will cause issues similar to #4739 and #5987.

Language / Project Type / NetBeans Component

No response

How to reproduce

Run the following code on the EDT:

DialogDescriptor first = new DialogDescriptor("Parent is the main window", "First");
DialogDisplayer.getDefault().notify(first);

DialogDescriptor second = new DialogDescriptor("Parent is first's dialog", "Second");
DialogDisplayer.getDefault().notify(second);

The first dialog will have the main window as the parent, but the second will have the dialog created for first even though it has been closed.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Linux

JDK

21.0.5

Apache NetBeans packaging

Apache NetBeans platform

Anything else

Here's what seems to be happening:

  1. Closing the first dialog submits a WINDOW_CLOSED event to the event queue
  2. Before the event is processed, notify opens the second dialog
  3. This end up in DialogDisplayerImpl.AWTQuery.showDialog() which ultimately gets the new dialog’s parent using org.openide.util.Utilities.findDialogParent
  4. This returns the active window from KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() which is still the now closed first dialog because the WINDOW_CLOSED event hasn’t yet been processed

Updating Utilities.findDialogParent to resolve a suggested parent via the closed window's owner would probably resolve the issue. Something like this after the modal check may work:

if (parent instanceof Window w) {
    while (!w.isVisible()) {
        w = w.getOwner();
        if (w == null) {
            break;
        }
    }
    parent = w;
}

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Contribution welcomeAn issue or feature not currently being worked on, but a contribution would be welcomed!Platform[ci] enable platform tests (platform/*)kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions