Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6613060

Persisting JFrame with XMLEncoder gives error in Java SE 6

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: client-libs
    • Labels:

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0_02"
        Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
        Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux thinkpad-x60 2.6.20-16-generic #2 SMP Sun Sep 23 19:50:39 UTC 2007 i686 GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        Saving a JFrame with XMLEncoder gives the error report shown below.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the program that follows. Click Save. Type test.xml for the file name. Watch the error report.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        I expected not to see an error report. (There was none under SE 5.0)
        ACTUAL -
        I saw the aforementioned error report.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.InstantiationException: javax.swing.BufferStrategyPaintManager$BufferInfo
        Continuing ...
        java.lang.Exception: XMLEncoder: discarding statement JFrame.addWindowListener(BufferStrategyPaintManager$BufferInfo);
        Continuing ...

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------

        import java.awt.*;
        import java.awt.event.*;
        import java.beans.*;
        import java.io.*;
        import javax.swing.*;

        /**
           This program demonstrates the use of an XML encoder and decoder to save and restore a frame.
        */
        public class PersistentFrameTest
        {
           public static void main(String[] args)
           {
              chooser = new JFileChooser();
              chooser.setCurrentDirectory(new File("."));
              PersistentFrameTest test = new PersistentFrameTest();
              test.init();
           }

           public void init()
           {
              frame = new JFrame();
              frame.setLayout(new FlowLayout());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setTitle("PersistentFrameTest");
              frame.setSize(400, 200);

              JButton loadButton = new JButton("Load");
              frame.add(loadButton);
              loadButton.addActionListener(EventHandler.create(ActionListener.class, this, "load"));

              JButton saveButton = new JButton("Save");
              frame.add(saveButton);
              saveButton.addActionListener(EventHandler.create(ActionListener.class, this, "save"));
             
              frame.setVisible(true);
           }

           public void load()
           {
              // show file chooser dialog
              int r = chooser.showOpenDialog(null);

              // if file selected, open
              if(r == JFileChooser.APPROVE_OPTION)
              {
                 try
                 {
                    File file = chooser.getSelectedFile();
                    XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
                    decoder.readObject();
                    decoder.close();
                 }
                 catch (IOException e)
                 {
                    JOptionPane.showMessageDialog(null, e);
                 }
              }
           }

           public void save()
           {
              if(chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
              {
                 try
                 {
                    File file = chooser.getSelectedFile();
                    XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
                    encoder.writeObject(frame);
                    encoder.close();
                 }
                 catch (IOException e)
                 {
                    JOptionPane.showMessageDialog(null, e);
                 }
              }
           }

           private static JFileChooser chooser;
           private JFrame frame;
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Close both eyes when the program runs.

        Release Regression From : 5.0
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                malenkov Sergey Malenkov (Inactive)
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: