[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Some object serialization problems for discussion(4)-ObjectInputS tream
From: |
Wu, Gansha |
Subject: |
Some object serialization problems for discussion(4)-ObjectInputS tream |
Date: |
Fri, 3 Aug 2001 08:49:54 +0800 |
We have many chances that Classpath classes have different object layout
(e.g, private fields) from JDK classes, so when we construct class according
to an object stream generated by JDK, issues happened in
ObjectInputStream.readFields(): even the field name doesn't exist in local
class, we still call setXXXField to set it, then exception happens and program
halts. So we might add a try-catch to wrap setXXXField, that's to say, to
ignore
it and try to continue, but not halt.
The patch is like this:
private void readFields (Object obj, ObjectStreamField[] stream_fields,
boolean call_read_method,
ObjectStreamClass stream_osc)
throws ClassNotFoundException, IOException
{
... ...
while (stream_idx < stream_fields.length
&& real_idx < real_fields.length)
{
... ...
+ try{
if (type == Boolean.TYPE)
{
... ...
if (set_value)
setBooleanField (obj, field_name, value);
}
else if (type == Byte.TYPE)
{
... ...
if (set_value)
setByteField (obj, field_name, value);
}
else if (type == Character.TYPE)
{
... ...
if (set_value)
setCharField (obj, field_name, value);
}
else if (type == Double.TYPE)
{
... ...
if (set_value)
setDoubleField (obj, field_name, value);
}
else if (type == Float.TYPE)
{
... ...
if (set_value)
setFloatField (obj, field_name, value);
}
else if (type == Integer.TYPE)
{
... ...
if (set_value)
setIntField (obj, field_name, value);
}
else if (type == Long.TYPE)
{
... ...
if (set_value)
setLongField (obj, field_name, value);
}
else if (type == Short.TYPE)
{
... ...
if (set_value)
setShortField (obj, field_name, value);
}
else
{
Object value =
default_initialize ? null : readObject ();
if (set_value)
setObjectField (obj, field_name,
real_field.getTypeString (), value);
}
+ }catch(NoSuchFieldError ex){
+ // DEBUGln ("Field '" + field_name + "' doesn't not exist in local " +
stream_osc.forClass());
+ }
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Some object serialization problems for discussion(4)-ObjectInputS tream,
Wu, Gansha <=