JDK-6332297 : REGRESSION: Tool Tips don't work after serialize/deserialize
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-10-04
  • Updated: 2011-02-16
  • Resolved: 2006-03-30
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 6
6 b78Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The bug occurs when you deserialize a component.  The tool tip associated with the component is lost.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.) javac ToolTipTest.java
2.) java ToolTipTest


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Hover over the buttons in the 3rd window.  Tool tips should be displayed.
ACTUAL -
  Tool tips are only displayed in the first window.

With JRE 1.4.2 and JRE 1.3.0, Tool tips are displayed in the third window.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;
import javax.swing.*;

/*
 * This class demonstrates 2 bugs in JRE 5.0 update 5.  The first bug occurs
 * when you Java serialize a component.  The tool tip associated with the
 * component is lost.  The second bug occurs when you deserialize a component.
 * The tool tip associated with the component is lost.
 *
 * To witness the behavior, run this class with no arguments.  3 windows will
 * pop up with descriptive title bar's.  The original window will have a button
 * with a working tool tip.  The middle window is a new window which has been
 * serialized.  The tool tips don't work on this one.  The third is the
 * reserialization of the second window.  Tools tips don't work here either.
 *
 * I believe the first bug could be fixed by adding a
 * ToolTipManager.registerComponent call to the end of the
 * JComponent.writeObject method.
 *
 * I believe the second bug could be fixed by moving the call to
 * ToolTipManager->registerComponent, inside JComponent.readObject, after the
 * client properties have been read.
 *
 */
public class ToolTipTest extends JFrame
    {

    public static int positionOffset = 0;

    public ToolTipTest (String id)
        {
        setTitle("Tool Tip Test: " + id);

        JButton button =
            new JButton ("This is a button with tool tip text: " + id);

        getContentPane().add(button);
        button.setToolTipText("Tool Tip Test: " + id);
        getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
        pack();
        setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        positionWindow();
        }

    public void positionWindow ()
        {
        Point position = new Point(positionOffset, positionOffset);
        positionOffset += 100;
        setLocation (position);
        }

    static public void main(String args[])
        {
        try {
            ToolTipTest toolTipTest = new ToolTipTest("Original");

            ToolTipTest toolTipTest2 = new ToolTipTest("To be serialized");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(toolTipTest2);

            ByteArrayInputStream bais = new
                ByteArrayInputStream(baos.toByteArray());

            ObjectInputStream oins = new ObjectInputStream(bais);
            Object o = oins.readObject();

            ToolTipTest toolTipTest3 = (ToolTipTest) o;
            toolTipTest3.setTitle("TTT Reserialized");
            toolTipTest3.setVisible(true);
            toolTipTest3.positionWindow();
            }
        catch (Exception ex)
            {
            ex.printStackTrace();
            }
        }
    }

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

CUSTOMER SUBMITTED WORKAROUND :
String t = comp.getToolTipText();
comp.setToolTipText(null);
comp.setToolTipText(t);


Release Regression From : 1.4.2_09
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Comments
EVALUATION For reference, this was broken by 4864304, which made many performance improvements to Swing. Before 4864304, client properties used to be stored in a HashTable which was serializable. With this change, they now use a transient ArrayTable and there's code to serialize/deserialize them. But the code to read them was put in readObject() too late. It needed to happen sooner. Hence this fix.
28-03-2006

EVALUATION JComponent stores toolTipText in a client property, but in JComponent.readObject() we ask a component for its toolTipText *before* clientProperties are set; it leads to incorrect behaviour
13-03-2006