-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
hopper
-
x86
-
linux
-
Verified
Name: rmT116609 Date: 11/04/2001
Java (TM) 2 Runtime Enviroment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
Instances of javax.swing.JSpinner can only be serialized once.
The second attempt to serialize the object results in a NotSerializableException of class javax.swing.plaf.basic.BasicSpinnerUI$SpinnerLayout.
The problem is reproducible on Windows 2000(SP 2), Solaris 2.8, Linux Redhat 6.2 using JDK1.4.0-beta3
***************************************************************************
Example to reproduce the error:
import java.io.*;
import javax.swing.* ;
public class SerializableCheck
{
public static void main (String[] args) throws Exception
{
// Use one of these classes and everything works fine.
//final JComponent originalComponent = new JComboBox() ;
//final JComponent originalComponent = new JList() ;
//final JComponent originalComponent = new JTextField() ;
//final JComponent originalComponent = new JFormattedTextField() ;
// Use a JSpinner and it crashs
final JComponent originalComponent = new JSpinner() ;
JComponent firstCopiedComponent = null ;
System.out.println ( "doing FIRST call to deepCopy(originalComponent)" ) ;
firstCopiedComponent = (JComponent) deepCopy ( originalComponent ) ;
System.out.println ( "copy first copy again ..." ) ;
deepCopy ( firstCopiedComponent ) ;
System.out.println ( "doing SECOND call to deepCopy(originalComponent)" ) ;
deepCopy ( originalComponent ) ;
}
private static Object deepCopy ( java.io.Serializable objectToCopy ) throws IOException, ClassNotFoundException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream ( baos ) ;
oos.writeObject ( objectToCopy ) ;
ByteArrayInputStream bais = new ByteArrayInputStream ( baos.toByteArray() ) ;
ObjectInputStream ois = new ObjectInputStream ( bais ) ;
return ois.readObject() ;
}
}
***************************************************************************
Output of the program:
doing FIRST call to deepCopy(originalComponent)
copy first copy again ...
doing SECOND call to deepCopy(originalComponent)
Exception in thread "main" java.io.NotSerializableException: javax.swing.plaf.basic.BasicSpinnerUI$SpinnerLayout
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1057)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1333)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:370)
at java.awt.Container.writeObject(Container.java:2536)
at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28)
at java.lang.reflect.Method.invoke(Method.java:327)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:783)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1297)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1248)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1055)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:281)
at de.cursor.gui.mrv.SerializableCheck.deepCopy(SerializableCheck.java:37)
at de.cursor.gui.mrv.SerializableCheck.main(SerializableCheck.java:28)
(Review ID: 134962)
======================================================================
- relates to
-
JDK-4408047 Regression: new serialization model can lead to NotSerializableExceptions
-
- Resolved
-