/[classpath]/classpath/java/io/ObjectOutputStream.java
ViewVC logotype

Diff of /classpath/java/io/ObjectOutputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.51 by tromey, Sat Nov 6 22:58:53 2004 UTC revision 1.52 by jfrijters, Wed Dec 1 10:13:33 2004 UTC
# Line 250  public class ObjectOutputStream extends Line 250  public class ObjectOutputStream extends
250                  break;                  break;
251                }                }
252    
253                Class clazz = obj.getClass();
254                ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);
255                if (osc == null)
256                  throw new NotSerializableException(clazz.getName());
257                
258              if ((replacementEnabled || obj instanceof Serializable)              if ((replacementEnabled || obj instanceof Serializable)
259                  && ! replaceDone)                  && ! replaceDone)
260                {                {
# Line 257  public class ObjectOutputStream extends Line 262  public class ObjectOutputStream extends
262                                    
263                  if (obj instanceof Serializable)                  if (obj instanceof Serializable)
264                    {                    {
                     Method m = null;  
265                      try                      try
266                        {                        {
267                          Class classArgs[] = {};                          Method m = osc.writeReplaceMethod;
268                          m = getMethod(obj.getClass(), "writeReplace",                          if (m != null)
269                                        classArgs);                              obj = m.invoke(obj, new Object[0]);
                         // m can't be null by definition since an  
                         // exception would have been thrown so a check  
                         // for null is not needed.  
                         obj = m.invoke(obj, new Object[] {});  
                       }  
                     catch (NoSuchMethodException ignore)  
                       {  
270                        }                        }
271                      catch (IllegalAccessException ignore)                      catch (IllegalAccessException ignore)
272                        {                        {
# Line 294  public class ObjectOutputStream extends Line 291  public class ObjectOutputStream extends
291                  break;                  break;
292                }                }
293    
             Class clazz = obj.getClass();  
             ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);  
             if (osc == null)  
               throw new NotSerializableException(clazz.getName());  
               
294              if (clazz.isArray ())              if (clazz.isArray ())
295                {                {
296                  realOutput.writeByte(TC_ARRAY);                  realOutput.writeByte(TC_ARRAY);
# Line 1261  public class ObjectOutputStream extends Line 1253  public class ObjectOutputStream extends
1253    private void callWriteMethod(Object obj, ObjectStreamClass osc)    private void callWriteMethod(Object obj, ObjectStreamClass osc)
1254      throws IOException      throws IOException
1255    {    {
     Class klass = osc.forClass();  
1256      currentPutField = null;      currentPutField = null;
1257      try      try
1258        {        {
1259          Class classArgs[] = {ObjectOutputStream.class};          Object args[] = {this};
1260          Method m = getMethod(klass, "writeObject", classArgs);          osc.writeObjectMethod.invoke(obj, args);
         Object args[] = {this};  
         m.invoke(obj, args);      
       }  
     catch (NoSuchMethodException nsme)  
       {  
         // Nothing.  
1261        }        }
1262      catch (InvocationTargetException x)      catch (InvocationTargetException x)
1263        {        {
# Line 1283  public class ObjectOutputStream extends Line 1268  public class ObjectOutputStream extends
1268          if (exception instanceof IOException)          if (exception instanceof IOException)
1269            throw (IOException) exception;            throw (IOException) exception;
1270    
1271          IOException ioe          IOException ioe
1272            = new IOException("Exception thrown from writeObject() on " +            = new IOException("Exception thrown from writeObject() on " +
1273                              klass + ": " + exception.getClass().getName());                              osc.forClass().getName() + ": " +
1274                                exception.getClass().getName());
1275          ioe.initCause(exception);          ioe.initCause(exception);
1276          throw ioe;          throw ioe;
1277        }        }
# Line 1293  public class ObjectOutputStream extends Line 1279  public class ObjectOutputStream extends
1279        {        {
1280          IOException ioe          IOException ioe
1281            = new IOException("Failure invoking writeObject() on " +            = new IOException("Failure invoking writeObject() on " +
1282                              klass + ": " + x.getClass().getName());                              osc.forClass().getName() + ": " +
1283                                x.getClass().getName());
1284          ioe.initCause(x);          ioe.initCause(x);
1285          throw ioe;          throw ioe;
1286        }        }
# Line 1535  public class ObjectOutputStream extends Line 1522  public class ObjectOutputStream extends
1522        }        }
1523    }    }
1524    
   private Method getMethod (Class klass, String name, Class[] args)  
     throws java.lang.NoSuchMethodException  
   {  
     final Method m = klass.getDeclaredMethod(name, args);  
     setAccessible.setMember(m);  
     AccessController.doPrivileged(setAccessible);  
     return m;  
   }  
   
1525    private void dumpElementln (String msg)    private void dumpElementln (String msg)
1526    {    {
1527      for (int i = 0; i < depth; i++)      for (int i = 0; i < depth; i++)

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26