title: ANdroid Serialization causes ConcurrentModificationException. How can I avoid this?
body: <p>On serialization my object which is a custom class, holding various ArrayLists, every so often I get a Concurrent Mod Exception. Clearly one or more of the arraylists is throwing this. But I don't know where, or how to fix it. Implementing an iterator would be my first idea, but how to go about doing that for serialization?</p>
  
  <p>This is my serialization code:<code>enter code here</code></p>
  
  <pre><code> try{
      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
  
      try { 
            ObjectOutput out = new ObjectOutputStream(bos); 
            out.writeObject(TGame);
  
            // Get the bytes of the serialized object 
            byte[] buf = bos.toByteArray(); 
  
            File sdCard = Environment.getExternalStorageDirectory();
            File dir = new File (sdCard.getAbsolutePath() + "/game_folder");
            dir.mkdirs();
            File file = new File(dir, "serializationtest");
  
  
            FileOutputStream fos = new FileOutputStream(file);
                //this.openFileOutput(filename, Context.MODE_PRIVATE);
            fos.write(buf);
            fos.close(); 
          } catch(IOException ioe) { 
            Log.e("serializeObject", "error", ioe); 
  
  
          }catch(StackOverflowError e){
              //do something
          }
  
          File f =this.getDir(filename, 0);
          Log.v("FILE SAVED",f.getName());    
      }catch(ConcurrentModificationException e){
          //do something          
      }
  }
  </code></pre>