ConcurrentModificationException with writeObject
<p>I have the following (simplified) code periodically run by a Thread in the class <code>A</code> (once per second):</p>

<pre><code>Socket s = new Socket(IP,PORT);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
synchronized(this) {
   oos.writeObject(this);   //Exception HERE
   oos.flush();
}
...
</code></pre>

<p>The object (<code>this</code>) to send through the socket has an object of the class <code>B</code> as instance variable and <code>B</code> has a <code>LinkedList&lt;Long&gt;</code> as instance variable.</p>

<p>The application throws <code>ConcurrentModificationException</code>:</p>

<pre><code>E/AndroidRuntime(681): FATAL EXCEPTION: Thread-10
E/AndroidRuntime(681): java.util.ConcurrentModificationException
E/AndroidRuntime(681): at java.util.LinkedList$LinkIterator.next(LinkedList.java:124)
E/AndroidRuntime(681): at java.util.LinkedList.writeObject(LinkedList.java:973)
E/AndroidRuntime(681): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(681): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1219)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.util.LinkedList.writeObject(LinkedList.java:973)
E/AndroidRuntime(681): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(681): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1219)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at qoe.Application.connectUpdate(Application.java:194)
E/AndroidRuntime(681): at qoe.Application.access$0(Application.java:183)
E/AndroidRuntime(681): at qoe.Application$AutoUpdate.run(Application.java:217)
</code></pre>

<p>I run this app in Android with Eclipse and AVD, Windows 7 x64. Thanks in advance.</p>

<p>Edit: After many tests I think that the method that could cause problem is the following:</p>

<pre><code>/* Instance variables */
private LinkedList&lt;Long&gt; mylist;
private long value;
/* The incriminated method */
public synchronized void myBadMethod() {
   this.mylist.add(this.value);
}
</code></pre>
