|
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
|
|
Comments
|
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
|