"Wu, Gansha" <[EMAIL PROTECTED]> writes:

> About the serialization of Throwable:
> 
> Consider the snippet from Throwable.java:
> 
>     private void writeObject(java.io.ObjectOutputStream s) 
>     throws IOException
>     {
>       ObjectOutputStream.PutField oFields;
>       oFields = s.putFields();
>       oFields.put("detailMessage", message);
>       s.writeFields(); 
>     }
> 
>   private void readObject(java.io.ObjectInputStream s)
>     throws IOException, ClassNotFoundException
>     {
>       ObjectInputStream.GetField oFields;
>       oFields = s.readFields();
>       message = (String)oFields.get("detailMessage", (String)null);
>     }
> 
>    here a "detailMessage" field is going to be added to serialized field list 
> in ObjectOutputStream.PutField. I understand here we want to keep binary 
> compatible with Sun JDK. But what's a pity here is our Throwable has no private 
> field named "detailMessage" here, only "message" field. So when come to 
> ObjectOutputStream.PutField.put("detailMessage", message):
> 
>    public PutField putFields () throws IOException
>    {  ... ...
>       currentPutField = new PutField ()
>       { ... ...
>                  public void put (String name, Object value)
>         throws IOException, IllegalArgumentException
>         {
>           ObjectStreamField field
>             = currentObjectStreamClass.getField (name);                              
>           
>                <- Here return null to "field", and all the following steps will fail
> 
>           if (value != null &&
>               ! field.getType ().isAssignableFrom (value.getClass ()))
>             throw new IllegalArgumentException ();
>           objs[field.getOffset ()] = value;
>         }
>             ... ...
>       }
>       So I wonder if here we could add some mapping mechanisms to map real field 
>names 
> to serialized strings, e.g: add a member function like:
> 
>       public void put (String field_name, String serialized_name, Object value)
>         throws IOException, IllegalArgumentException
>        Let Throwable be wise about the mapping when doing stuff in 
>readObject/writeObject.
>  I wonder if it will bring more issues in ObjectInputStream.

Is this all to say that ObjectStreamClass.getField (String) can return
null, such that the line 

objs[field.getOffset ()] = value;

throws an exception?

I don't understand the mapping problem you're talking about.

Brian
-- 
Brian Jones <[EMAIL PROTECTED]>

_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to