title: ClassCastException ObjectStreamClass cannot be cast to java.lang.String when deserializing
body: <p>I am trying to serialize, send and receive an instance of the below class ( ServerGameDataObject object = new ServerGameDataObject() )</p>
  
  <pre><code>public class ServerGameDataObject implements Serializable {
      private static final long serialVersionUID = 5410058267505412928L;
  
      private TestClass t1 =null;
      private TestClass t2 =null;
  
      public ServerGameDataObject(){
  
          t1 = new TestClass();
          t2 = new TestClass();
  
      }
  }
  </code></pre>
  
  <p>The definition of TestClass in it is :</p>
  
  <pre><code>import java.io.Serializable;
  
  
  public class TestClass  implements Serializable{
      transient public static final long serialVersionUID = -3089302783006861199L;
  
      private int val =-1;
      public  TestClass(){
          val=-1;
  
      }
  }
  </code></pre>
  
  <p>.....
  The object is sent as follows:</p>
  
  <pre><code>    ObjectOutputStream o = new AppendingObjectOutputStream(
              &lt;some outputstream&gt;);
  
      o.writeUnshared(object);
      o.flush();
  </code></pre>
  
  <p>The definition of AppendingObjectOutputStream is:</p>
  
  <pre><code>public class AppendingObjectOutputStream extends ObjectOutputStream {
  
      public AppendingObjectOutputStream(OutputStream out) throws IOException {
          super(out);
      }
  
      @Override
      protected void writeStreamHeader() throws IOException {
          // do not write a header, but reset:
          // this line added after another question
          // showed a problem with the original
          reset();
      }
  
  }
  
  
  
   The code on the receiving end is :
  
      Object o = null;
     while ((o = inputStream.readUnshared()) != null) { // this is Receiver.java, line 74
      ...
      }
  
  inputStream is an instance of ObjectInputStream 
  </code></pre>
  
  <p>On the receiving end this exception is thrown:</p>
  
  <pre><code>&gt; 05-10 10:54:51.572: E/AndroidRuntime(3133): FATAL EXCEPTION:
  &gt; Thread-134 05-10 10:54:51.572: E/AndroidRuntime(3133):
  &gt; java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast
  &gt; to java.lang.String 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readFieldDescriptors(ObjectInputStream.java:935)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:1744)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1656)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1806)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readObject(ObjectInputStream.java:2006)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readObject(ObjectInputStream.java:1963)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1140)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1372)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1269)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1858)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readObject(ObjectInputStream.java:2006)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:1978)
  &gt; 05-10 10:54:51.572: E/AndroidRuntime(3133):   at
  &gt; Receiver.run(Receiver.java:74)
  </code></pre>
  
  <p>If inside ServerGameDataObject I define t2 to be transient (transient private TestClass t2 =null; ), then I DO REICEIVE the objects</p>
  
  <p>What's wrong? Why can i NOT receive both t1 and t2 ?</p>