Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4630761
Votes 8
Synopsis HTMLDocument not serializable
Category java:classes_swing
Reported Against merlin-rc1
Release Fixed mustang(b80)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs
Submit Date 30-JAN-2002
Description


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


FULL OPERATING SYSTEM VERSION :
 customer  7.2 (i386), glibc-2.2.2-38
Linux linux 2.4.4-4GB #1 Wed May 16 00:37:55 GMT 2001 i686
unknown


A DESCRIPTION OF THE PROBLEM :
The HTMLDocument doesn't seem to be serializable. I tried
with this class:

,----[ Test.java ]
| class Test {
| 
|     public static void main(String[] args) throws
Exception {
|         URL url = new URL(args[0]);
|         InputStream uin = url.openStream();
| 
|         HTMLDocument doc = new HTMLDocument();
|         HTMLEditorKit kit = new HTMLEditorKit();
|         kit.read(uin, doc, 0);
| 
|         ByteArrayOutputStream out = new
ByteArrayOutputStream();
|         ObjectOutputStream oos = new ObjectOutputStream(
out );
|         oos.writeObject(doc);
|         oos.flush();
|         oos.close();
|         
|         ByteArrayInputStream in = new
ByteArrayInputStream( out.toByteArray() );
|         ObjectInputStream oin = new ObjectInputStream(
`----

And I got this exception:

| Exception in thread "main"
java.io.NotSerializableException: javax.swing.text.html.Map

I tried with JDK 1.4b3, too, but it didn't change a thing.
It's especially tough since the HTMLDocument even declares
to be serializable.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Execute the above class, you'll see.



EXPECTED VERSUS ACTUAL BEHAVIOR :
I wanted to serialize an HTMLDocument, including all
pictures and other linked content (such as JavaScripts
etc.)

Instead, nothing was serialized but an exception thrown.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
,----[ STDERR ]
| Exception in thread "main" java.io.NotSerializableException:
javax.swing.text.html.Map
|         at
java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
|         at java.util.Hashtable.writeObject(Hashtable.java:757)
|         at java.lang.reflect.Method.invoke(Native Method)
|         at
java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1864)
|         at
java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1210)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
|         at java.util.Hashtable.writeObject(Hashtable.java:757)
|         at java.lang.reflect.Method.invoke(Native Method)
|         at
java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1864)
|         at
java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1210)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
|         at
java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1827)
|         at
java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
|         at
java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
|         at Test.main(Test.java:19)
| 
`----



This bug can be reproduced always.

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

class HtmlTest {

    public static void main(String[] args) throws Exception {
        URL url = new URL(args[0]);
        InputStream uin = url.openStream();

        HTMLDocument doc = new HTMLDocument();
        HTMLEditorKit kit = new HTMLEditorKit();
        kit.read(uin, doc, 0);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream( out );
        oos.writeObject(doc);
        oos.flush();
        oos.close();
        
        ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray()
);
        ObjectInputStream oin = new ObjectInputStream( in );
        
        HTMLDocument newDoc = (HTMLDocument) oin.readObject();

        JFrame frame = new JFrame("test");
        frame.getContentPane().add( new JTextPane(newDoc) );
        frame.setSize( new Dimension(800, 600) );
        frame.show();
    }
}


---------- END SOURCE ----------
(Review ID: 137961) 
======================================================================
Posted Date : 2006-02-06 23:50:20.0
Work Around
N/A
Evaluation




(  xxxxx@xxxxx  )

The bug has two parts: 
1) AbstractDocument is not serializable because:
 when bug 4434319 has been fixed the new property "MultiByteProperty"
 has been added to class AbstractDocument. This property is instance of class
 "Object" (not String) which is NOT serializable.
 When HTMLDocument is required to be serialized it tries to make writeObject
 for member "documentProperties". Since one of "documentProperties" is
 MultiByteProperty attempt to make "writeObject" failes.
 I didn't find any comments about 
 need to have MultiByteProperty as instance of Object.
 So I think that it will be OK to make MultiByteProperty
 the instance of String.

2) classes Map and Option are not serializable (these
  classes don't implement interface Serializable).
  When html document has appropriate tags (Map and/or Option) then
  class HTMLDocument has the properties with values of
  instances of classes Map and/or Option.
  It cause raising of java.io.NotSerializableException during
  serialization of HTMLDocument.
  To fix this problem it is enough to declare
  each of these classes "implements Serializable"

======================================================================
Posted Date : 2006-02-07 00:44:30.0

Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=11245&forumID=1463
Posted Date : 2006-02-06 23:48:49.0
Comments
  
  Include a link with my name & email   

Submitted On 08-FEB-2002
potel
Same bug occurs in Windows 1.4rc


Submitted On 31-JAN-2005
potel
Still doesn't work in JDK 1.5.0 (b64).


Submitted On 01-DEC-2006
payday
NOT fixed in JSE 1.6 beta2, STILL doesn't serialize.  If you don't believe me just try serializing the document generated with:

JEditorPane jep = new JEditorPane("http://java.sun.com");
HTMLDocument doc = (HTMLDocument) jep.getDocument();

It fails, with: javax.swing.text.html.CSS$Value is not serializable as a value in an AttributeSet

What is going on??  This bug has been around since 1999...



PLEASE NOTE: JDK6 is formerly known as Project Mustang