United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6613060 Persisting JFrame with XMLEncoder gives error in Java SE 6
JDK-6613060 : Persisting JFrame with XMLEncoder gives error in Java SE 6

Details
Type:
Bug
Submit Date:
2007-10-04
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2010-05-24
Component:
client-libs
OS:
linux
Sub-Component:
java.beans
CPU:
x86
Priority:
P3
Resolution:
Cannot Reproduce
Affected Versions:
6
Fixed Versions:
7

Related Reports
Backport:

Sub Tasks

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.

                                    

Comments
EVALUATION

XMLEncoder does not support private classes i.e. javax.swing.BufferStrategyPaintManager$BufferInfo because of security. Seems we should create additional persistence delegate for this class in the MetaData.java file.
                                     
2007-11-19
EVALUATION

It is not reproducible since b76 at least.
                                     
2010-05-24



Hardware and Software, Engineered to Work Together