11/*
2- * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test
26- * @bug 4938801
26+ * @bug 4938801 8376169
2727 * @key headful
2828 * @summary Verifies popup is removed when the component is removed
2929 * @run main TestPopupInvoker
3030 */
3131
3232import java .awt .BorderLayout ;
33+ import java .awt .Component ;
3334import java .awt .Container ;
3435import java .awt .Robot ;
3536import java .util .concurrent .CountDownLatch ;
@@ -48,6 +49,7 @@ public class TestPopupInvoker {
4849 static JFrame frame ;
4950 static JLabel label ;
5051 static Container pane ;
52+ static volatile Component invoker ;
5153
5254 private static final CountDownLatch popupShown = new CountDownLatch (1 );
5355 private static final CountDownLatch popupHidden = new CountDownLatch (1 );
@@ -73,6 +75,7 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
7375 @ Override
7476 public void popupMenuWillBecomeInvisible (PopupMenuEvent e ) {
7577 popupHidden .countDown ();
78+ popupMenu .setInvoker (null );
7679 }
7780
7881 @ Override
@@ -106,6 +109,11 @@ public static void main(String[] args) throws Exception {
106109 if (!popupHidden .await (1 , SECONDS )) {
107110 throw new RuntimeException ("Popup is visible after component is removed" );
108111 }
112+
113+ SwingUtilities .invokeAndWait (() -> invoker = popupMenu .getInvoker ());
114+ if (invoker != null ) {
115+ throw new RuntimeException ("Invoker is not null" );
116+ }
109117 } finally {
110118 SwingUtilities .invokeAndWait (() -> {
111119 if (frame != null ) {
0 commit comments