classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some object serialization problems for discussion(2)-Throwable


From: Brian Jones
Subject: Re: Some object serialization problems for discussion(2)-Throwable
Date: 04 Aug 2001 09:43:28 -0400
User-agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7

"Wu, Gansha" <address@hidden> 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 <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]