On Wed, 30 Jul 2025 12:59:37 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>> Yes, it seems deserialized JPopupMenu fails hiding the popup menu owing to 
>> `propListener` not getting serialized.
>> 
>> Tried with modified testcase of yours and fixed in latest PR
>> 
>> 
>> import java.awt.*;
>> import java.awt.event.*;
>> import javax.swing.*;
>> import java.beans.PropertyChangeListener;
>> import java.io.*;
>> 
>> public class JPopupMenuSerializationTest {
>> 
>>     public static class MyThread implements Runnable {
>>         static Container box;
>>         static Component invo;
>> 
>>         public MyThread(Container cont, Component comp) {
>>             this.invo = comp;
>>             this.box = cont;
>>         }
>> 
>>         public void run() {
>>             System.out.println("Starting 3 second countdown...");
>>             try{
>>                 Thread.currentThread().sleep(3000);
>>             } catch (Exception e) {}
>>             System.out.println("Removing popup invoker from the container.");
>>             box.remove(invo);
>>             box.repaint();
>>         }
>>     }
>> 
>>     public static void main(String[] args) throws Exception {
>>         JPopupMenuSerializationTest test = new JPopupMenuSerializationTest();
>>         test.testSerialization();
>>     }
>> 
>>     public void testSerialization() throws Exception {
>>         JPopupMenu popupMenu = new JPopupMenu();
>>         byte[] data = serialize(popupMenu);
>>         JPopupMenu copy = deserialize(data);
>> 
>>         test(copy);
>>     }
>> 
>>     private void test(JPopupMenu jpm) {
>>         JFrame frame = new JFrame("My frame");
>>         final Container pane = frame.getContentPane();
>>         pane.setLayout(new BorderLayout());
>>         pane.add(new JTextField("", 20), BorderLayout.NORTH);
>>         JButton btn = new JButton("Exit");
>>         final Thread[] thr = new Thread[] { null };
>>         btn.setAction(new AbstractAction() {
>>             public void actionPerformed(ActionEvent ev) {
>>                 System.exit(0);
>>             }
>>         });
>>         btn.setText("Exit");
>>         pane.add(btn, BorderLayout.SOUTH);
>>         final JLabel label = new JLabel("Click here to invoke popup");
>>         label.addMouseListener(new MouseAdapter() {
>>             public void mouseReleased(MouseEvent e) {
>>                 jpm.add("One");
>>                 jpm.add("Two");
>>                 jpm.add("Three");
>>                 jpm.show(label,
>>                         label.getLocationOnScreen().x,
>>                         label.getLocationOnScreen().y);
>>             }
>> 
>>...
>
> Do we even care about serialisation as much?
> 
> What would be the use case?

Does the `invoker` instance serialise registered listeners?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26407#discussion_r2242626737

Reply via email to