You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Vasily Zakharov (JIRA)" <ji...@apache.org> on 2006/07/25 07:09:16 UTC

[jira] Updated: (HARMONY-969) java.util.TreeMap throws NotSerializableException

     [ http://issues.apache.org/jira/browse/HARMONY-969?page=all ]

Vasily Zakharov updated HARMONY-969:
------------------------------------

    Attachment: SerializationTreeMap.patch

Here's the suggested patch to resolve the problem.


> java.util.TreeMap throws NotSerializableException
> -------------------------------------------------
>
>                 Key: HARMONY-969
>                 URL: http://issues.apache.org/jira/browse/HARMONY-969
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: SerializationTreeMap.patch
>
>
> NotSerializableException occurs when trying to serialize a java.util.TreeMap object that has entrySet() method called before.
> The cause for this is TreeMap class is serialized by defaultWriteObject(), and it contains a non-transient field, entrySet, that is initialized in entrySet() method by an instance of AbstractSet class that is not Serializable.
> Suggested fix: make entrySet field transient.
> Here's the code to reproduce the bug:
> import java.io.*;
> import java.util.*;
> public class SerializationTreeMapTest {
>     public static void main(String[] args) {
>         try {
>             TreeMap map = new TreeMap();
>             map.entrySet();
>             ByteArrayOutputStream bOut = new ByteArrayOutputStream();
>             ObjectOutputStream oOut = new ObjectOutputStream(bOut);
>             oOut.writeObject(map);
>             System.out.println("SUCCESS");
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
> and here's the output:
> C:\> java SerializationTreeMapTest
> java.io.NotSerializableException: java.util.TreeMap$1
>         at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1624)
>         at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1932)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1768)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1732)
>         at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1241)
>         at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:327)
>         at java.util.TreeMap.writeObject(TreeMap.java:1422)
>         at java.lang.reflect.VMReflection.invokeMethod(VMReflection.java)
>         at java.lang.reflect.Method.invoke(Method.java:183)
>         at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1318)
>         at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1658)
>         at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1932)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1768)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1732)
>         at SerializationTreeMapTest.main(SerializationTreeMapTest.java:11)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira