JDK-4994649 : Long term persistence fails for JLayeredPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-02-13
  • Updated: 2010-07-09
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b15Fixed
Related Reports
Relates :  
Description
Name: gm110360			Date: 02/13/2004


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
JLayeredPane does not seem to support serialization via the java.beans XMLEncoder / XMLDecoder methods.  The components that are added to the layered pane lose their layer attributes during serialization (they simply don't appear in the XML file), and they therefore do not appear during de-serialisation.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a JLayeredPane, with several overlapping components.
2. Serialize.
3. Deserialize.
4. Observe that no components are displayed.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That the components will be displayed on the de-serialized JLayeredPane in the correct layering order as they were at at the time of serialization.
ACTUAL -
No components are displayed at all.  Additionally, no layer information appears to exist in the XML serialization file.

REPRODUCIBILITY :
This bug can be reproduced always.

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

import javax.swing.*;
import java.awt.*;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.*;

public class test
{
	public static String fileName = "LPTest.xml";

	public static void main(String[] args)
	{
		if (args.length != 1)
		{
			System.out.println("java test [serialize|deserialize]");
			System.exit(1);
		}

		JFrame f = new JFrame("test");
		JLayeredPane lp = null;

		if (args[0].toLowerCase().equals("serialize"))
			lp = test.serialize();
		else if (args[0].toLowerCase().equals("deserialize"))
			lp = test.deserialize();
		else
		{
			System.out.println("Invalid argument!");
			System.exit(1);
		}

		lp.setSize(200,200);
		f.setSize(200,200);
		f.getContentPane().add(lp);
		f.setVisible(true);
	}

	public static JLayeredPane serialize()
	{
		JLayeredPane lp = new JLayeredPane();
		lp.setSize(200,200);

		JPanel pan1 = new JPanel();
		pan1.setBackground(Color.blue);
		pan1.setLocation(0,0);
		pan1.setSize(50,50);

		JPanel pan2 = new JPanel();
		pan2.setBackground(Color.red);
		pan2.setLocation(25,25);
		pan2.setSize(50,50);

		JPanel pan3 = new JPanel();
		pan3.setBackground(Color.yellow);
		pan3.setLocation(40,40);
		pan3.setSize(50,50);

		lp.add(pan2, new Integer(0));
		lp.add(pan1, new Integer(1));
		lp.add(pan3, new Integer(2));

		try
		{
			XMLEncoder e = new XMLEncoder(
					new BufferedOutputStream(
						new FileOutputStream(fileName)));

			e.writeObject(lp);
			e.flush();
			e.close();
		}
		catch (FileNotFoundException e1)
		{
			System.out.println("Failed to write to " + fileName);
			System.exit(1);
		}

		return lp;
	}

	public static JLayeredPane deserialize()
	{
		JLayeredPane lp = null;
		try
		{
			XMLDecoder d = new XMLDecoder(
			        new BufferedInputStream(
			                new FileInputStream(fileName)));
			lp = (JLayeredPane) d.readObject();
			d.close();
		}
		catch (FileNotFoundException e)
		{
			System.out.println("Serialisation file " + fileName + " did not exist!");
			System.exit(1);
		}

		if (lp == null)
		{
			System.out.println("Serialisation file " + fileName + " did not contain a valid component!");
			System.exit(1);
		}

		return lp;
	}

}

---------- END SOURCE ----------
(Incident Review ID: 187506) 
======================================================================

Comments
SUGGESTED FIX See attached webrev.
20-04-2006

EVALUATION We don't need to introduce persistance delegate for JLayeredPane because there is only one bug with this class. I allowed to write bounds of subcomponents which parent is JLayeredPane. Also, I fixed method of writing subcomponents with constraints. I used method add(Component,Object,int) because JLayeredPane has Integer constraints. I can't use method add(Component,Object) because method add(Component,int) is called instead.
21-11-2005

EVALUATION The bug 4950972 depends on this one.
15-11-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

EVALUATION Reproducible as described since 1.4. Should fix. ###@###.### 2004-02-23 We need to introduce persistance delegate for JLayeredPane like it's mentioned in a number of bugs. ###@###.### 2005-06-06 15:47:12 GMT
23-02-2004