You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Spark Shen <sm...@gmail.com> on 2006/08/07 08:44:49 UTC

[classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Hi:
This is a long post, thanks for your patient to read it through :-)

I wrote a test case as below:
public void test_SubMap_Serializable() throws Exception {
        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
        map.put(1, 2.1);
        map.put(2, 3.1);
        map.put(3, 4.5);
        map.put(7, 21.3);
        SortedMap<Integer, Double> headMap = map.headMap(3);
        assertTrue(headMap instanceof Serializable);
        assertFalse(headMap instanceof TreeMap);
        assertTrue(headMap instanceof SortedMap);
}
Which says the returned headMap is not a TreeMap but a serializable 
SortedMap. 

IIRC, there are three mysterious serialized form immediately following 
the serialized form of java.util.TreeMap. They are

Class **java.util.TreeMap$1** extends Object implements Serializable

Class **java.util.TreeMap$2** extends Object implements Serializable

Class **java.util.TreeMap$3** extends Object implements Serializable

respectively. This gives a hint that there are three inner classes of 
TreeMap which should be serializable.
But what are they indeed?
IMHO, the returned SortedMap may
be one of the java.util.TreeMap$x classes. What is your opinion? (I 
raised JIRA-1066 for this)

The above test case suggests me to make the returned SortedMap 
serializable. But, I have another concern:
SortedMap returned by TreeMap is not a public class(does not have a 
documented Serialized form), and the serialization behavior of this 
SortedMap is strange. See the test case below:
public void test_HeadMap_Serializable() throws Exception {
        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
        map.put(1, 2.1);
        map.put(2, 3.1);
        map.put(3, 4.5);
        map.put(7, 21.3);
        SortedMap<Integer, Double> headMap = map.headMap(3);
        assertTrue(headMap instanceof Serializable);
        assertFalse(headMap instanceof TreeMap);
        assertTrue(headMap instanceof SortedMap);
       
         // Write the SortedMap out and read it back.
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(headMap);
        oos.close();

        ByteArrayInputStream bis = new 
ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        Object outputObject = (Object) ois.readObject();
       
        *assertNull(((SortedMap)outputObject).entrySet());

        assertNotNull(((SortedMap)outputObject).keySet());

        assertNotNull(((SortedMap)outputObject).values());

*        *// assertEquals(outputObject, headMap);*
}

The commented out assertion will throw out a NullPointerException, and 
the entrySet of the SortedMap is Null while keySet and values are not.
This is strange. Do we need to follow RI to make the returned SortedMap 
serializable like this?

Best regards

-- 
Spark Shen
China Software Development Lab, IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Ilya Okomin <il...@gmail.com>.
On 8/7/06, Spark Shen <sm...@gmail.com> wrote:

> Hi:
> This is a long post, thanks for your patient to read it through :-)
>
> I wrote a test case as below:
> public void test_SubMap_Serializable() throws Exception {
>        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>        map.put(1, 2.1);
>        map.put(2, 3.1);
>        map.put(3, 4.5);
>        map.put(7, 21.3);
>        SortedMap<Integer, Double> headMap = map.headMap(3);
>        assertTrue(headMap instanceof Serializable);
>        assertFalse(headMap instanceof TreeMap);
>        assertTrue(headMap instanceof SortedMap);
> }
> Which says the returned headMap is not a TreeMap but a serializable
> SortedMap.
>
> IIRC, there are three mysterious serialized form immediately following
> the serialized form of java.util.TreeMap. They are
>
> Class **java.util.TreeMap$1** extends Object implements Serializable
>
> Class **java.util.TreeMap$2** extends Object implements Serializable
>
> Class **java.util.TreeMap$3** extends Object implements Serializable
>
> respectively. This gives a hint that there are three inner classes of
> TreeMap which should be serializable.
> But what are they indeed?
> IMHO, the returned SortedMap may
> be one of the java.util.TreeMap$x classes. What is your opinion? (I
> raised JIRA-1066 for this)
>
> The above test case suggests me to make the returned SortedMap
> serializable. But, I have another concern:
> SortedMap returned by TreeMap is not a public class(does not have a
> documented Serialized form), and the serialization behavior of this
> SortedMap is strange. See the test case below:
> public void test_HeadMap_Serializable() throws Exception {
>        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>        map.put(1, 2.1);
>        map.put(2, 3.1);
>        map.put(3, 4.5);
>        map.put(7, 21.3);
>        SortedMap<Integer, Double> headMap = map.headMap(3);
>        assertTrue(headMap instanceof Serializable);
>        assertFalse(headMap instanceof TreeMap);
>        assertTrue(headMap instanceof SortedMap);
>
>         // Write the SortedMap out and read it back.
>         ByteArrayOutputStream bos = new ByteArrayOutputStream();
>        ObjectOutputStream oos = new ObjectOutputStream(bos);
>        oos.writeObject(headMap);
>        oos.close();
>
>        ByteArrayInputStream bis = new
> ByteArrayInputStream(bos.toByteArray());
>        ObjectInputStream ois = new ObjectInputStream(bis);
>        Object outputObject = (Object) ois.readObject();
>
>        *assertNull(((SortedMap)outputObject).entrySet());
>
>        assertNotNull(((SortedMap)outputObject).keySet());
>
>        assertNotNull(((SortedMap)outputObject).values());
>
> *        *// assertEquals(outputObject, headMap);*
> }
>
> The commented out assertion will throw out a NullPointerException, and
> the entrySet of the SortedMap is Null while keySet and values are not.
> This is strange. Do we need to follow RI to make the returned SortedMap
> serializable like this?


Following the spec, Map object equals to given object if they are both
implements Map and they are represents the same mapping. If the outputObject
has null entry set I suppose NPE on RI could be a result of unhandled access
to a null entry set object.
As for private SortedMap implementation for TreeMap.headMap() serialization
issue, IMHO on Harmony it works correctly and we shouldn't follow RI
behaviour. I don't see any reasons to return null as a result of entrySet()
call instead of set view of the mappings after deserialization.



> Best regards
>
> --
> Spark Shen
> China Software Development Lab, IBM
>
>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
--
Ilya Okomin
Intel Middleware Products Division

Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Spark Shen <sm...@gmail.com>.
2006/8/8, Oleg Khaschansky <ol...@gmail.com>:
>
> > Shall we follow RI on this odd behavior in harmony?
>
> My opinion is that we should not. But if 1.5 has deserialization issue
> it won't be possible to make it read SubMap, serialized by harmony,
> correctly. And I think this it's not a problem for us.


Hi:
I agree with your opinion that

"It will be broken in the same way with RI and work correct with Harmony
classlib... "

That is to say, SubMap on harmony should be self compatible when
serialized/deserialized. While
using harmony to serialize SubMap and RI to deserialize SubMap, the behavior
should be the same
as using RI itself to serialize/deserialize SubMap. A little Tricky. :-)

Best regards


On 8/8/06, Spark Shen <sm...@gmail.com> wrote:
> > Hi, thank you for your information.
> >
> > I slightly modified my second test case and run it on JDK6-beta.
> >
> > public void test_HeadMap_Serializable() throws Exception {
> > // same as before
> >
> > *assertNotNull(((SortedMap)outputObject).entrySet()); // This line
> > assertNull previously.*
> >
> > assertNotNull(((SortedMap)outputObject).keySet());
> >
> > assertNotNull(((SortedMap)outputObject).values());
> >
> > *assertEquals(outputObject, headMap); // This line is previously
> > commented out, and now passes on JDK6.*
> > }
> > IMO, this shows that Inner classes of TreeMap on JDK5 do not have proper
> > serialization behavior. Shall we follow RI on this odd behavior in
> harmony?
> > Personally, I am against this.
> >
> > Best regards
> >
> > Oleg Khaschansky 写道:
> > > Hi,
> > >
> > > Take a look at this:
> > > http://download.java.net/jdk6/docs/api/serialized-form.html
> > > Maybe this document will give you an idea of what are those inner
> > > classes... Of cause, in the new release serialized form may have
> > > changed.
> > >
> > > --
> > > Oleg
> > >
> > > On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> > >> Hi:
> > >> This is a long post, thanks for your patient to read it through :-)
> > >>
> > >> I wrote a test case as below:
> > >> public void test_SubMap_Serializable() throws Exception {
> > >> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >> map.put(1, 2.1);
> > >> map.put(2, 3.1);
> > >> map.put(3, 4.5);
> > >> map.put(7, 21.3);
> > >> SortedMap<Integer, Double> headMap = map.headMap(3);
> > >> assertTrue(headMap instanceof Serializable);
> > >> assertFalse(headMap instanceof TreeMap);
> > >> assertTrue(headMap instanceof SortedMap);
> > >> }
> > >> Which says the returned headMap is not a TreeMap but a serializable
> > >> SortedMap.
> > >>
> > >> IIRC, there are three mysterious serialized form immediately
> following
> > >> the serialized form of java.util.TreeMap. They are
> > >>
> > >> Class **java.util.TreeMap$1** extends Object implements Serializable
> > >>
> > >> Class **java.util.TreeMap$2** extends Object implements Serializable
> > >>
> > >> Class **java.util.TreeMap$3** extends Object implements Serializable
> > >>
> > >> respectively. This gives a hint that there are three inner classes of
> > >> TreeMap which should be serializable.
> > >> But what are they indeed?
> > >> IMHO, the returned SortedMap may
> > >> be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > >> raised JIRA-1066 for this)
> > >>
> > >> The above test case suggests me to make the returned SortedMap
> > >> serializable. But, I have another concern:
> > >> SortedMap returned by TreeMap is not a public class(does not have a
> > >> documented Serialized form), and the serialization behavior of this
> > >> SortedMap is strange. See the test case below:
> > >> public void test_HeadMap_Serializable() throws Exception {
> > >> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >> map.put(1, 2.1);
> > >> map.put(2, 3.1);
> > >> map.put(3, 4.5);
> > >> map.put(7, 21.3);
> > >> SortedMap<Integer, Double> headMap = map.headMap(3);
> > >> assertTrue(headMap instanceof Serializable);
> > >> assertFalse(headMap instanceof TreeMap);
> > >> assertTrue(headMap instanceof SortedMap);
> > >>
> > >> // Write the SortedMap out and read it back.
> > >> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > >> ObjectOutputStream oos = new ObjectOutputStream(bos);
> > >> oos.writeObject(headMap);
> > >> oos.close();
> > >>
> > >> ByteArrayInputStream bis = new
> > >> ByteArrayInputStream(bos.toByteArray());
> > >> ObjectInputStream ois = new ObjectInputStream(bis);
> > >> Object outputObject = (Object) ois.readObject();
> > >>
> > >> *assertNull(((SortedMap)outputObject).entrySet());
> > >>
> > >> assertNotNull(((SortedMap)outputObject).keySet());
> > >>
> > >> assertNotNull(((SortedMap)outputObject).values());
> > >>
> > >> * *// assertEquals(outputObject, headMap);*
> > >> }
> > >>
> > >> The commented out assertion will throw out a NullPointerException,
> and
> > >> the entrySet of the SortedMap is Null while keySet and values are
> not.
> > >> This is strange. Do we need to follow RI to make the returned
> SortedMap
> > >> serializable like this?
> > >>
> > >> Best regards
> > >>
> > >> --
> > >> Spark Shen
> > >> China Software Development Lab, IBM
> > >>
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> Terms of use : http://incubator.apache.org/harmony/mailing.html
> > >> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > >> For additional commands, e-mail:
> harmony-dev-help@incubator.apache.org
> > >>
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> > >
> > >
> >
> >
> > --
> > Spark Shen
> > China Software Development Lab, IBM
> >
> >
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Spark Shen
China Software Development Lab, IBM

Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Oleg Khaschansky <ol...@gmail.com>.
> Shall we follow RI on this odd behavior in harmony?

My opinion is that we should not. But if 1.5 has deserialization issue
it won't be possible to make it read SubMap, serialized by harmony,
correctly. And I think this it's not a problem for us.

On 8/8/06, Spark Shen <sm...@gmail.com> wrote:
> Hi, thank you for your information.
>
> I slightly modified my second test case and run it on JDK6-beta.
>
> public void test_HeadMap_Serializable() throws Exception {
> // same as before
>
> *assertNotNull(((SortedMap)outputObject).entrySet()); // This line
> assertNull previously.*
>
> assertNotNull(((SortedMap)outputObject).keySet());
>
> assertNotNull(((SortedMap)outputObject).values());
>
> *assertEquals(outputObject, headMap); // This line is previously
> commented out, and now passes on JDK6.*
> }
> IMO, this shows that Inner classes of TreeMap on JDK5 do not have proper
> serialization behavior. Shall we follow RI on this odd behavior in harmony?
> Personally, I am against this.
>
> Best regards
>
> Oleg Khaschansky 写道:
> > Hi,
> >
> > Take a look at this:
> > http://download.java.net/jdk6/docs/api/serialized-form.html
> > Maybe this document will give you an idea of what are those inner
> > classes... Of cause, in the new release serialized form may have
> > changed.
> >
> > --
> > Oleg
> >
> > On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> >> Hi:
> >> This is a long post, thanks for your patient to read it through :-)
> >>
> >> I wrote a test case as below:
> >> public void test_SubMap_Serializable() throws Exception {
> >> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> >> map.put(1, 2.1);
> >> map.put(2, 3.1);
> >> map.put(3, 4.5);
> >> map.put(7, 21.3);
> >> SortedMap<Integer, Double> headMap = map.headMap(3);
> >> assertTrue(headMap instanceof Serializable);
> >> assertFalse(headMap instanceof TreeMap);
> >> assertTrue(headMap instanceof SortedMap);
> >> }
> >> Which says the returned headMap is not a TreeMap but a serializable
> >> SortedMap.
> >>
> >> IIRC, there are three mysterious serialized form immediately following
> >> the serialized form of java.util.TreeMap. They are
> >>
> >> Class **java.util.TreeMap$1** extends Object implements Serializable
> >>
> >> Class **java.util.TreeMap$2** extends Object implements Serializable
> >>
> >> Class **java.util.TreeMap$3** extends Object implements Serializable
> >>
> >> respectively. This gives a hint that there are three inner classes of
> >> TreeMap which should be serializable.
> >> But what are they indeed?
> >> IMHO, the returned SortedMap may
> >> be one of the java.util.TreeMap$x classes. What is your opinion? (I
> >> raised JIRA-1066 for this)
> >>
> >> The above test case suggests me to make the returned SortedMap
> >> serializable. But, I have another concern:
> >> SortedMap returned by TreeMap is not a public class(does not have a
> >> documented Serialized form), and the serialization behavior of this
> >> SortedMap is strange. See the test case below:
> >> public void test_HeadMap_Serializable() throws Exception {
> >> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> >> map.put(1, 2.1);
> >> map.put(2, 3.1);
> >> map.put(3, 4.5);
> >> map.put(7, 21.3);
> >> SortedMap<Integer, Double> headMap = map.headMap(3);
> >> assertTrue(headMap instanceof Serializable);
> >> assertFalse(headMap instanceof TreeMap);
> >> assertTrue(headMap instanceof SortedMap);
> >>
> >> // Write the SortedMap out and read it back.
> >> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> >> ObjectOutputStream oos = new ObjectOutputStream(bos);
> >> oos.writeObject(headMap);
> >> oos.close();
> >>
> >> ByteArrayInputStream bis = new
> >> ByteArrayInputStream(bos.toByteArray());
> >> ObjectInputStream ois = new ObjectInputStream(bis);
> >> Object outputObject = (Object) ois.readObject();
> >>
> >> *assertNull(((SortedMap)outputObject).entrySet());
> >>
> >> assertNotNull(((SortedMap)outputObject).keySet());
> >>
> >> assertNotNull(((SortedMap)outputObject).values());
> >>
> >> * *// assertEquals(outputObject, headMap);*
> >> }
> >>
> >> The commented out assertion will throw out a NullPointerException, and
> >> the entrySet of the SortedMap is Null while keySet and values are not.
> >> This is strange. Do we need to follow RI to make the returned SortedMap
> >> serializable like this?
> >>
> >> Best regards
> >>
> >> --
> >> Spark Shen
> >> China Software Development Lab, IBM
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> Terms of use : http://incubator.apache.org/harmony/mailing.html
> >> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> >> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
> Spark Shen
> China Software Development Lab, IBM
>
>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Spark Shen <sm...@gmail.com>.
Hi, thank you for your information.

I slightly modified my second test case and run it on JDK6-beta.

public void test_HeadMap_Serializable() throws Exception {
// same as before

*assertNotNull(((SortedMap)outputObject).entrySet()); // This line 
assertNull previously.*

assertNotNull(((SortedMap)outputObject).keySet());

assertNotNull(((SortedMap)outputObject).values());

*assertEquals(outputObject, headMap); // This line is previously 
commented out, and now passes on JDK6.*
}
IMO, this shows that Inner classes of TreeMap on JDK5 do not have proper 
serialization behavior. Shall we follow RI on this odd behavior in harmony?
Personally, I am against this.

Best regards

Oleg Khaschansky 写道:
> Hi,
>
> Take a look at this: 
> http://download.java.net/jdk6/docs/api/serialized-form.html
> Maybe this document will give you an idea of what are those inner
> classes... Of cause, in the new release serialized form may have
> changed.
>
> -- 
> Oleg
>
> On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
>> Hi:
>> This is a long post, thanks for your patient to read it through :-)
>>
>> I wrote a test case as below:
>> public void test_SubMap_Serializable() throws Exception {
>> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>> map.put(1, 2.1);
>> map.put(2, 3.1);
>> map.put(3, 4.5);
>> map.put(7, 21.3);
>> SortedMap<Integer, Double> headMap = map.headMap(3);
>> assertTrue(headMap instanceof Serializable);
>> assertFalse(headMap instanceof TreeMap);
>> assertTrue(headMap instanceof SortedMap);
>> }
>> Which says the returned headMap is not a TreeMap but a serializable
>> SortedMap.
>>
>> IIRC, there are three mysterious serialized form immediately following
>> the serialized form of java.util.TreeMap. They are
>>
>> Class **java.util.TreeMap$1** extends Object implements Serializable
>>
>> Class **java.util.TreeMap$2** extends Object implements Serializable
>>
>> Class **java.util.TreeMap$3** extends Object implements Serializable
>>
>> respectively. This gives a hint that there are three inner classes of
>> TreeMap which should be serializable.
>> But what are they indeed?
>> IMHO, the returned SortedMap may
>> be one of the java.util.TreeMap$x classes. What is your opinion? (I
>> raised JIRA-1066 for this)
>>
>> The above test case suggests me to make the returned SortedMap
>> serializable. But, I have another concern:
>> SortedMap returned by TreeMap is not a public class(does not have a
>> documented Serialized form), and the serialization behavior of this
>> SortedMap is strange. See the test case below:
>> public void test_HeadMap_Serializable() throws Exception {
>> TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>> map.put(1, 2.1);
>> map.put(2, 3.1);
>> map.put(3, 4.5);
>> map.put(7, 21.3);
>> SortedMap<Integer, Double> headMap = map.headMap(3);
>> assertTrue(headMap instanceof Serializable);
>> assertFalse(headMap instanceof TreeMap);
>> assertTrue(headMap instanceof SortedMap);
>>
>> // Write the SortedMap out and read it back.
>> ByteArrayOutputStream bos = new ByteArrayOutputStream();
>> ObjectOutputStream oos = new ObjectOutputStream(bos);
>> oos.writeObject(headMap);
>> oos.close();
>>
>> ByteArrayInputStream bis = new
>> ByteArrayInputStream(bos.toByteArray());
>> ObjectInputStream ois = new ObjectInputStream(bis);
>> Object outputObject = (Object) ois.readObject();
>>
>> *assertNull(((SortedMap)outputObject).entrySet());
>>
>> assertNotNull(((SortedMap)outputObject).keySet());
>>
>> assertNotNull(((SortedMap)outputObject).values());
>>
>> * *// assertEquals(outputObject, headMap);*
>> }
>>
>> The commented out assertion will throw out a NullPointerException, and
>> the entrySet of the SortedMap is Null while keySet and values are not.
>> This is strange. Do we need to follow RI to make the returned SortedMap
>> serializable like this?
>>
>> Best regards
>>
>> -- 
>> Spark Shen
>> China Software Development Lab, IBM
>>
>>
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Spark Shen
China Software Development Lab, IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Oleg Khaschansky <ol...@gmail.com>.
> Do you have any ideas where these classes can appear? As far as I
> understand TreeMap#headMap() as well as #subMap() and #tailMap()
> returns instances of TreeMap$SubMap.
Yes.

> IMHO if we cannot get instances
> of these $1 - $3 classes we should not care about it.
But we can get SubMap instance. And its serialization/deserialization
is partly broken in RI. As far as I understood the question is: should
we implement the functionality that is partly broken in RI? But if
there is SubMap already in the TreeMap, why not make a compatible
serialization for it, knowing form? It will be broken in the same way
with RI and work correct with Harmony classlib...

On 8/7/06, Alexei Zakharov <al...@gmail.com> wrote:
> Hi Spark,
>
> > > > IIRC, there are three mysterious serialized form immediately following
> > > > the serialized form of java.util.TreeMap. They are
> > > > Class **java.util.TreeMap$1**
> > > > Class **java.util.TreeMap$2**
> > > > Class **java.util.TreeMap$3**
>
> Do you have any ideas where these classes can appear? As far as I
> understand TreeMap#headMap() as well as #subMap() and #tailMap()
> returns instances of TreeMap$SubMap. IMHO if we cannot get instances
> of these $1 - $3 classes we should not care about it. There are
> several places in the J2SE 5.0 api doc where serialization form for
> non-public classes is described.
>
> Regards,
>
> 2006/8/7, Ilya Okomin <il...@gmail.com>:
> > On 8/7/06, Oleg Khaschansky <ol...@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > Take a look at this:
> > > http://download.java.net/jdk6/docs/api/serialized-form.html
> > > Maybe this document will give you an idea of what are those inner
> > > classes... Of cause, in the new release serialized form may have
> > > changed.
> >
> >
> > Oleg, ASFAIK the main issue is that TreeMap.headMap() returns the private
> > implemention of SortedMap class. This SortedMap implementation serializable
> > on RI, but it is undocumented in the spec. Spark Shen has just provided
> > tests that show strange behavior of serialization and deserialization of
> > this SortedMap implementation on RI.
> > I'm not sure we can find anything usefull on the link you've provided,
> > because there only serialization forms for public classes are described (if
> > I'm not mistaken:)).
> >
> > Thanks,
> > Ilya.
> >
> > --
> > > Oleg
> > >
> > > On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> > > > Hi:
> > > > This is a long post, thanks for your patient to read it through :-)
> > > >
> > > > I wrote a test case as below:
> > > > public void test_SubMap_Serializable() throws Exception {
> > > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > > >        map.put(1, 2.1);
> > > >        map.put(2, 3.1);
> > > >        map.put(3, 4.5);
> > > >        map.put(7, 21.3);
> > > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > > >        assertTrue(headMap instanceof Serializable);
> > > >        assertFalse(headMap instanceof TreeMap);
> > > >        assertTrue(headMap instanceof SortedMap);
> > > > }
> > > > Which says the returned headMap is not a TreeMap but a serializable
> > > > SortedMap.
> > > >
> > > > IIRC, there are three mysterious serialized form immediately following
> > > > the serialized form of java.util.TreeMap. They are
> > > >
> > > > Class **java.util.TreeMap$1** extends Object implements Serializable
> > > >
> > > > Class **java.util.TreeMap$2** extends Object implements Serializable
> > > >
> > > > Class **java.util.TreeMap$3** extends Object implements Serializable
> > > >
> > > > respectively. This gives a hint that there are three inner classes of
> > > > TreeMap which should be serializable.
> > > > But what are they indeed?
> > > > IMHO, the returned SortedMap may
> > > > be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > > > raised JIRA-1066 for this)
> > > >
> > > > The above test case suggests me to make the returned SortedMap
> > > > serializable. But, I have another concern:
> > > > SortedMap returned by TreeMap is not a public class(does not have a
> > > > documented Serialized form), and the serialization behavior of this
> > > > SortedMap is strange. See the test case below:
> > > > public void test_HeadMap_Serializable() throws Exception {
> > > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > > >        map.put(1, 2.1);
> > > >        map.put(2, 3.1);
> > > >        map.put(3, 4.5);
> > > >        map.put(7, 21.3);
> > > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > > >        assertTrue(headMap instanceof Serializable);
> > > >        assertFalse(headMap instanceof TreeMap);
> > > >        assertTrue(headMap instanceof SortedMap);
> > > >
> > > >         // Write the SortedMap out and read it back.
> > > >         ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > > >        ObjectOutputStream oos = new ObjectOutputStream(bos);
> > > >        oos.writeObject(headMap);
> > > >        oos.close();
> > > >
> > > >        ByteArrayInputStream bis = new
> > > > ByteArrayInputStream(bos.toByteArray());
> > > >        ObjectInputStream ois = new ObjectInputStream(bis);
> > > >        Object outputObject = (Object) ois.readObject();
> > > >
> > > >        *assertNull(((SortedMap)outputObject).entrySet());
> > > >
> > > >        assertNotNull(((SortedMap)outputObject).keySet());
> > > >
> > > >        assertNotNull(((SortedMap)outputObject).values());
> > > >
> > > > *        *// assertEquals(outputObject, headMap);*
> > > > }
> > > >
> > > > The commented out assertion will throw out a NullPointerException, and
> > > > the entrySet of the SortedMap is Null while keySet and values are not.
> > > > This is strange. Do we need to follow RI to make the returned SortedMap
> > > > serializable like this?
> > > >
> > > > Best regards
> > > >
> > > > --
> > > > Spark Shen
> > > > China Software Development Lab, IBM
> > > >
> > --
> > Ilya Okomin
> > Intel Middleware Products Division
> >
> >
>
>
> --
> Alexei Zakharov,
> Intel Middleware Product Division
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Alexei Zakharov <al...@gmail.com>.
Hi Spark,

> > > IIRC, there are three mysterious serialized form immediately following
> > > the serialized form of java.util.TreeMap. They are
> > > Class **java.util.TreeMap$1**
> > > Class **java.util.TreeMap$2**
> > > Class **java.util.TreeMap$3**

Do you have any ideas where these classes can appear? As far as I
understand TreeMap#headMap() as well as #subMap() and #tailMap()
returns instances of TreeMap$SubMap. IMHO if we cannot get instances
of these $1 - $3 classes we should not care about it. There are
several places in the J2SE 5.0 api doc where serialization form for
non-public classes is described.

Regards,

2006/8/7, Ilya Okomin <il...@gmail.com>:
> On 8/7/06, Oleg Khaschansky <ol...@gmail.com> wrote:
> >
> > Hi,
> >
> > Take a look at this:
> > http://download.java.net/jdk6/docs/api/serialized-form.html
> > Maybe this document will give you an idea of what are those inner
> > classes... Of cause, in the new release serialized form may have
> > changed.
>
>
> Oleg, ASFAIK the main issue is that TreeMap.headMap() returns the private
> implemention of SortedMap class. This SortedMap implementation serializable
> on RI, but it is undocumented in the spec. Spark Shen has just provided
> tests that show strange behavior of serialization and deserialization of
> this SortedMap implementation on RI.
> I'm not sure we can find anything usefull on the link you've provided,
> because there only serialization forms for public classes are described (if
> I'm not mistaken:)).
>
> Thanks,
> Ilya.
>
> --
> > Oleg
> >
> > On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> > > Hi:
> > > This is a long post, thanks for your patient to read it through :-)
> > >
> > > I wrote a test case as below:
> > > public void test_SubMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >        map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > > }
> > > Which says the returned headMap is not a TreeMap but a serializable
> > > SortedMap.
> > >
> > > IIRC, there are three mysterious serialized form immediately following
> > > the serialized form of java.util.TreeMap. They are
> > >
> > > Class **java.util.TreeMap$1** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$2** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$3** extends Object implements Serializable
> > >
> > > respectively. This gives a hint that there are three inner classes of
> > > TreeMap which should be serializable.
> > > But what are they indeed?
> > > IMHO, the returned SortedMap may
> > > be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > > raised JIRA-1066 for this)
> > >
> > > The above test case suggests me to make the returned SortedMap
> > > serializable. But, I have another concern:
> > > SortedMap returned by TreeMap is not a public class(does not have a
> > > documented Serialized form), and the serialization behavior of this
> > > SortedMap is strange. See the test case below:
> > > public void test_HeadMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >        map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > >
> > >         // Write the SortedMap out and read it back.
> > >         ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > >        ObjectOutputStream oos = new ObjectOutputStream(bos);
> > >        oos.writeObject(headMap);
> > >        oos.close();
> > >
> > >        ByteArrayInputStream bis = new
> > > ByteArrayInputStream(bos.toByteArray());
> > >        ObjectInputStream ois = new ObjectInputStream(bis);
> > >        Object outputObject = (Object) ois.readObject();
> > >
> > >        *assertNull(((SortedMap)outputObject).entrySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).keySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).values());
> > >
> > > *        *// assertEquals(outputObject, headMap);*
> > > }
> > >
> > > The commented out assertion will throw out a NullPointerException, and
> > > the entrySet of the SortedMap is Null while keySet and values are not.
> > > This is strange. Do we need to follow RI to make the returned SortedMap
> > > serializable like this?
> > >
> > > Best regards
> > >
> > > --
> > > Spark Shen
> > > China Software Development Lab, IBM
> > >
> --
> Ilya Okomin
> Intel Middleware Products Division
>
>


-- 
Alexei Zakharov,
Intel Middleware Product Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Oleg Khaschansky <ol...@gmail.com>.
Follow the link and take a close look at the classes after TreeMap's
form. There are serialization forms for the inner classes mentioned
above, am I correct?

On 8/7/06, Ilya Okomin <il...@gmail.com> wrote:
> On 8/7/06, Oleg Khaschansky <ol...@gmail.com> wrote:
> >
> > Hi,
> >
> > Take a look at this:
> > http://download.java.net/jdk6/docs/api/serialized-form.html
> > Maybe this document will give you an idea of what are those inner
> > classes... Of cause, in the new release serialized form may have
> > changed.
>
>
> Oleg, ASFAIK the main issue is that TreeMap.headMap() returns the private
> implemention of SortedMap class. This SortedMap implementation serializable
> on RI, but it is undocumented in the spec. Spark Shen has just provided
> tests that show strange behavior of serialization and deserialization of
> this SortedMap implementation on RI.
> I'm not sure we can find anything usefull on the link you've provided,
> because there only serialization forms for public classes are described (if
> I'm not mistaken:)).
>
> Thanks,
> Ilya.
>
> --
> > Oleg
> >
> > On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> > > Hi:
> > > This is a long post, thanks for your patient to read it through :-)
> > >
> > > I wrote a test case as below:
> > > public void test_SubMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >        map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > > }
> > > Which says the returned headMap is not a TreeMap but a serializable
> > > SortedMap.
> > >
> > > IIRC, there are three mysterious serialized form immediately following
> > > the serialized form of java.util.TreeMap. They are
> > >
> > > Class **java.util.TreeMap$1** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$2** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$3** extends Object implements Serializable
> > >
> > > respectively. This gives a hint that there are three inner classes of
> > > TreeMap which should be serializable.
> > > But what are they indeed?
> > > IMHO, the returned SortedMap may
> > > be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > > raised JIRA-1066 for this)
> > >
> > > The above test case suggests me to make the returned SortedMap
> > > serializable. But, I have another concern:
> > > SortedMap returned by TreeMap is not a public class(does not have a
> > > documented Serialized form), and the serialization behavior of this
> > > SortedMap is strange. See the test case below:
> > > public void test_HeadMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >        map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > >
> > >         // Write the SortedMap out and read it back.
> > >         ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > >        ObjectOutputStream oos = new ObjectOutputStream(bos);
> > >        oos.writeObject(headMap);
> > >        oos.close();
> > >
> > >        ByteArrayInputStream bis = new
> > > ByteArrayInputStream(bos.toByteArray());
> > >        ObjectInputStream ois = new ObjectInputStream(bis);
> > >        Object outputObject = (Object) ois.readObject();
> > >
> > >        *assertNull(((SortedMap)outputObject).entrySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).keySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).values());
> > >
> > > *        *// assertEquals(outputObject, headMap);*
> > > }
> > >
> > > The commented out assertion will throw out a NullPointerException, and
> > > the entrySet of the SortedMap is Null while keySet and values are not.
> > > This is strange. Do we need to follow RI to make the returned SortedMap
> > > serializable like this?
> > >
> > > Best regards
> > >
> > > --
> > > Spark Shen
> > > China Software Development Lab, IBM
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
> --
> Ilya Okomin
> Intel Middleware Products Division
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Ilya Okomin <il...@gmail.com>.
On 8/7/06, Ilya Okomin <il...@gmail.com> wrote:
>
>
>
>  On 8/7/06, Oleg Khaschansky <ol...@gmail.com> wrote:
> >
> > Hi,
> >
> > Take a look at this: http://download.java.net/jdk6/docs/api/serialized-form.html
> >
> > Maybe this document will give you an idea of what are those inner
> > classes... Of cause, in the new release serialized form may have
> > changed.
>
>
>  Oleg, ASFAIK the main issue is that TreeMap.headMap() returns the private
> implemention of SortedMap class. This SortedMap implementation serializable
> on RI, but it is undocumented in the spec. Spark Shen has just provided
> tests that show strange behavior of serialization and deserialization of
> this SortedMap implementation on RI.
> I'm not sure we can find anything usefull on the link you've provided,
> because there only serialization forms for public classes are described (if
> I'm not mistaken:)).
>
>

Seems to be I wasn't attentive enough to the link Oleg provided. There we
can found more detailed description of TreeMap inner classes serialization
forms than 1.5 spec has. I believe it will be usefull for us, thank you,
Oleg.

Regards,
Ilya.

  Thanks,
>  Ilya.
>
> --
> > Oleg
> >
> > On 8/7/06, Spark Shen <smallsmallorgan@gmail.com > wrote:
> > > Hi:
> > > This is a long post, thanks for your patient to read it through :-)
> > >
> > > I wrote a test case as below:
> > > public void test_SubMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >        map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > > }
> > > Which says the returned headMap is not a TreeMap but a serializable
> > > SortedMap.
> > >
> > > IIRC, there are three mysterious serialized form immediately following
> > > the serialized form of java.util.TreeMap. They are
> > >
> > > Class **java.util.TreeMap$1** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$2** extends Object implements Serializable
> > >
> > > Class **java.util.TreeMap$3** extends Object implements Serializable
> > >
> > > respectively. This gives a hint that there are three inner classes of
> > > TreeMap which should be serializable.
> > > But what are they indeed?
> > > IMHO, the returned SortedMap may
> > > be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > > raised JIRA-1066 for this)
> > >
> > > The above test case suggests me to make the returned SortedMap
> > > serializable. But, I have another concern:
> > > SortedMap returned by TreeMap is not a public class(does not have a
> > > documented Serialized form), and the serialization behavior of this
> > > SortedMap is strange. See the test case below:
> > > public void test_HeadMap_Serializable() throws Exception {
> > >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> > >         map.put(1, 2.1);
> > >        map.put(2, 3.1);
> > >        map.put(3, 4.5);
> > >        map.put(7, 21.3);
> > >        SortedMap<Integer, Double> headMap = map.headMap(3);
> > >        assertTrue(headMap instanceof Serializable);
> > >        assertFalse(headMap instanceof TreeMap);
> > >        assertTrue(headMap instanceof SortedMap);
> > >
> > >         // Write the SortedMap out and read it back.
> > >         ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > >        ObjectOutputStream oos = new ObjectOutputStream(bos);
> > >        oos.writeObject(headMap);
> > >        oos.close();
> > >
> > >        ByteArrayInputStream bis = new
> > > ByteArrayInputStream( bos.toByteArray());
> > >        ObjectInputStream ois = new ObjectInputStream(bis);
> > >        Object outputObject = (Object) ois.readObject();
> > >
> > >        *assertNull(((SortedMap)outputObject).entrySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).keySet());
> > >
> > >        assertNotNull(((SortedMap)outputObject).values());
> > >
> > > *        *// assertEquals(outputObject, headMap);*
> > > }
> > >
> > > The commented out assertion will throw out a NullPointerException, and
> > > the entrySet of the SortedMap is Null while keySet and values are not.
> > > This is strange. Do we need to follow RI to make the returned
> > SortedMap
> > > serializable like this?
> > >
> > > Best regards
> > >
> > > --
> > > Spark Shen
> > > China Software Development Lab, IBM
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
> --
> Ilya Okomin
> Intel Middleware Products Division
>



-- 
--
Ilya Okomin
Intel Middleware Products Division

Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Ilya Okomin <il...@gmail.com>.
On 8/7/06, Oleg Khaschansky <ol...@gmail.com> wrote:
>
> Hi,
>
> Take a look at this:
> http://download.java.net/jdk6/docs/api/serialized-form.html
> Maybe this document will give you an idea of what are those inner
> classes... Of cause, in the new release serialized form may have
> changed.


Oleg, ASFAIK the main issue is that TreeMap.headMap() returns the private
implemention of SortedMap class. This SortedMap implementation serializable
on RI, but it is undocumented in the spec. Spark Shen has just provided
tests that show strange behavior of serialization and deserialization of
this SortedMap implementation on RI.
I'm not sure we can find anything usefull on the link you've provided,
because there only serialization forms for public classes are described (if
I'm not mistaken:)).

Thanks,
Ilya.

--
> Oleg
>
> On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> > Hi:
> > This is a long post, thanks for your patient to read it through :-)
> >
> > I wrote a test case as below:
> > public void test_SubMap_Serializable() throws Exception {
> >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> >        map.put(1, 2.1);
> >        map.put(2, 3.1);
> >        map.put(3, 4.5);
> >        map.put(7, 21.3);
> >        SortedMap<Integer, Double> headMap = map.headMap(3);
> >        assertTrue(headMap instanceof Serializable);
> >        assertFalse(headMap instanceof TreeMap);
> >        assertTrue(headMap instanceof SortedMap);
> > }
> > Which says the returned headMap is not a TreeMap but a serializable
> > SortedMap.
> >
> > IIRC, there are three mysterious serialized form immediately following
> > the serialized form of java.util.TreeMap. They are
> >
> > Class **java.util.TreeMap$1** extends Object implements Serializable
> >
> > Class **java.util.TreeMap$2** extends Object implements Serializable
> >
> > Class **java.util.TreeMap$3** extends Object implements Serializable
> >
> > respectively. This gives a hint that there are three inner classes of
> > TreeMap which should be serializable.
> > But what are they indeed?
> > IMHO, the returned SortedMap may
> > be one of the java.util.TreeMap$x classes. What is your opinion? (I
> > raised JIRA-1066 for this)
> >
> > The above test case suggests me to make the returned SortedMap
> > serializable. But, I have another concern:
> > SortedMap returned by TreeMap is not a public class(does not have a
> > documented Serialized form), and the serialization behavior of this
> > SortedMap is strange. See the test case below:
> > public void test_HeadMap_Serializable() throws Exception {
> >        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
> >        map.put(1, 2.1);
> >        map.put(2, 3.1);
> >        map.put(3, 4.5);
> >        map.put(7, 21.3);
> >        SortedMap<Integer, Double> headMap = map.headMap(3);
> >        assertTrue(headMap instanceof Serializable);
> >        assertFalse(headMap instanceof TreeMap);
> >        assertTrue(headMap instanceof SortedMap);
> >
> >         // Write the SortedMap out and read it back.
> >         ByteArrayOutputStream bos = new ByteArrayOutputStream();
> >        ObjectOutputStream oos = new ObjectOutputStream(bos);
> >        oos.writeObject(headMap);
> >        oos.close();
> >
> >        ByteArrayInputStream bis = new
> > ByteArrayInputStream(bos.toByteArray());
> >        ObjectInputStream ois = new ObjectInputStream(bis);
> >        Object outputObject = (Object) ois.readObject();
> >
> >        *assertNull(((SortedMap)outputObject).entrySet());
> >
> >        assertNotNull(((SortedMap)outputObject).keySet());
> >
> >        assertNotNull(((SortedMap)outputObject).values());
> >
> > *        *// assertEquals(outputObject, headMap);*
> > }
> >
> > The commented out assertion will throw out a NullPointerException, and
> > the entrySet of the SortedMap is Null while keySet and values are not.
> > This is strange. Do we need to follow RI to make the returned SortedMap
> > serializable like this?
> >
> > Best regards
> >
> > --
> > Spark Shen
> > China Software Development Lab, IBM
> >
> >
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
--
Ilya Okomin
Intel Middleware Products Division

Re: [classlib][luni] Strange serialized form of java.util.TreeMap (re JIRA harmony-1066)

Posted by Oleg Khaschansky <ol...@gmail.com>.
Hi,

Take a look at this: http://download.java.net/jdk6/docs/api/serialized-form.html
Maybe this document will give you an idea of what are those inner
classes... Of cause, in the new release serialized form may have
changed.

--
  Oleg

On 8/7/06, Spark Shen <sm...@gmail.com> wrote:
> Hi:
> This is a long post, thanks for your patient to read it through :-)
>
> I wrote a test case as below:
> public void test_SubMap_Serializable() throws Exception {
>        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>        map.put(1, 2.1);
>        map.put(2, 3.1);
>        map.put(3, 4.5);
>        map.put(7, 21.3);
>        SortedMap<Integer, Double> headMap = map.headMap(3);
>        assertTrue(headMap instanceof Serializable);
>        assertFalse(headMap instanceof TreeMap);
>        assertTrue(headMap instanceof SortedMap);
> }
> Which says the returned headMap is not a TreeMap but a serializable
> SortedMap.
>
> IIRC, there are three mysterious serialized form immediately following
> the serialized form of java.util.TreeMap. They are
>
> Class **java.util.TreeMap$1** extends Object implements Serializable
>
> Class **java.util.TreeMap$2** extends Object implements Serializable
>
> Class **java.util.TreeMap$3** extends Object implements Serializable
>
> respectively. This gives a hint that there are three inner classes of
> TreeMap which should be serializable.
> But what are they indeed?
> IMHO, the returned SortedMap may
> be one of the java.util.TreeMap$x classes. What is your opinion? (I
> raised JIRA-1066 for this)
>
> The above test case suggests me to make the returned SortedMap
> serializable. But, I have another concern:
> SortedMap returned by TreeMap is not a public class(does not have a
> documented Serialized form), and the serialization behavior of this
> SortedMap is strange. See the test case below:
> public void test_HeadMap_Serializable() throws Exception {
>        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
>        map.put(1, 2.1);
>        map.put(2, 3.1);
>        map.put(3, 4.5);
>        map.put(7, 21.3);
>        SortedMap<Integer, Double> headMap = map.headMap(3);
>        assertTrue(headMap instanceof Serializable);
>        assertFalse(headMap instanceof TreeMap);
>        assertTrue(headMap instanceof SortedMap);
>
>         // Write the SortedMap out and read it back.
>         ByteArrayOutputStream bos = new ByteArrayOutputStream();
>        ObjectOutputStream oos = new ObjectOutputStream(bos);
>        oos.writeObject(headMap);
>        oos.close();
>
>        ByteArrayInputStream bis = new
> ByteArrayInputStream(bos.toByteArray());
>        ObjectInputStream ois = new ObjectInputStream(bis);
>        Object outputObject = (Object) ois.readObject();
>
>        *assertNull(((SortedMap)outputObject).entrySet());
>
>        assertNotNull(((SortedMap)outputObject).keySet());
>
>        assertNotNull(((SortedMap)outputObject).values());
>
> *        *// assertEquals(outputObject, headMap);*
> }
>
> The commented out assertion will throw out a NullPointerException, and
> the entrySet of the SortedMap is Null while keySet and values are not.
> This is strange. Do we need to follow RI to make the returned SortedMap
> serializable like this?
>
> Best regards
>
> --
> Spark Shen
> China Software Development Lab, IBM
>
>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org