classpath
[Top][All Lists]
Advanced

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

Some object serialization problems for discussion(2)-Throwable


From: Wu, Gansha
Subject: Some object serialization problems for discussion(2)-Throwable
Date: Wed, 1 Aug 2001 10:11:07 +0800

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.





reply via email to

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