[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ObjectInputStream & ObjectStreamClass problems (5)
From: |
Wu, Gansha |
Subject: |
ObjectInputStream & ObjectStreamClass problems (5) |
Date: |
Fri, 3 Aug 2001 11:04:42 +0800 |
Consider the following snippet in ObjectInputStream:
public final Object readObject () throws ClassNotFoundException, IOException
{
... ...
switch (marker){
case TC_CLASSDESC:{
... ...
setBlockDataMode (true);
osc.setClass (resolveClass (osc));
setBlockDataMode (false);
}
... ...
}
... ...
}
When we encounter class description, we must resolve it and add (Class,
ObjectStreamClass)
entry into ObjectStreamClass cache(ObjectStreamClass.classLookupTable), but in
ObjectStreamClass.java:
void setClass (Class clazz)
{
this.clazz = clazz;
}
Nothing is done with classLookupTable. The consequence is: when next time the
ObjectStreamClass for a specific Class is lookuped, nothing will be found and a
new ObjectStreamClass for the Class is created. See the following in
ObjectStreamClass.java:
public static ObjectStreamClass lookup (Class cl)
{
if (cl == null)
return null;
if (! (Serializable.class).isAssignableFrom (cl))
return null;
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);
if (osc != null)
return osc;
else
{
osc = new ObjectStreamClass (cl); <-----
classLookupTable.put (cl, osc);
return osc;
}
}
"new ObjectStreamClass (cl);" is called to create the ObjectStreamClass for
Class cl. Note: this time
ObjectStreamClass constructor will generate all the information about the Class
cl according to local
class definition but not the class description from the stream. e.g, it will
get fields information by
Field.getDeclaredFields(), but not fields information from stream.
So I think we might modify setClass like the following:
void setClass (Class clazz)
{
this.clazz = clazz;
+ ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (clazz);
+ if (osc == null)
+ classLookupTable.put (clazz, this);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- ObjectInputStream & ObjectStreamClass problems (5),
Wu, Gansha <=