title: Java Serialization with RMI
body: <p>I'm working on a project using Java RMI. 
  This is the class causing problem:</p>
  
  <pre><code>public class FSFile implements Serializable 
  {
  public static final int READ    = 0;
  public static final int WRITE   = 1;
  
  private int     flag;
  private String  filename;
  
  private transient BufferedWriter  writer;
  private transient BufferedReader  reader;
  
  ...
  
  private void writeObject(ObjectOutputStream stream) throws IOException
  {
      stream.defaultWriteObject();
      stream.writeObject(writer);
      stream.writeObject(reader);    
  }
  
  private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
  {
      stream.defaultReadObject();
      writer      = (BufferedWriter) stream.readObject();
      reader      = (BufferedReader) stream.readObject();
  }
  }
  </code></pre>
  
  <p>Basically, I use RMI to send that FSFile object to another process locally (for now) and here's the error I get:</p>
  
  <pre><code>java.rmi.UnmarshalException: error unmarshalling return; nested exception is:                                                                      
  java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException;
  java.io.BufferedReader
  </code></pre>
  
  <p>To be more precise, there's one class named FileService which use a function fetch() from a FileServer to get a FSFile in return. There is nothing special in the fetch() function, it just creates a FSFile and returns it. All communications between those classes are made via RMI.</p>
  
  <p>How come I have an error like this ?</p>