Program: 160262
Project: 160262
Buggy source:
/** 
 * attempt to reproduce - https://github.com/couchbase/couchbase-lite-android/issues/328 & - https://github.com/couchbase/couchbase-lite-android/issues/325
 */
public void testSetAttachmentsSequentiallyInTransaction() throws CouchbaseLiteException, IOException {
  boolean success=database.runInTransaction(new TransactionalTask(){
    public boolean run(){
      try {
        Document doc=database.createDocument();
        String id=doc.getId();
        InputStream jsonStream=getAsset("String_Node_Str");
        Map<String,Object> docProperties=null;
        docProperties=Manager.getObjectMapper().readValue(jsonStream,Map.class);
        docProperties.put("String_Node_Str",0);
        doc.putProperties(docProperties);
        jsonStream.close();
        UnsavedRevision rev=null;
        for (int i=0; i < 20; i++) {
          InputStream attachmentStream1=getAsset("String_Node_Str");
          Log.e(Database.TAG,"String_Node_Str" + i);
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 5,"String_Node_Str",attachmentStream1);
          rev.save();
          attachmentStream1.close();
          InputStream attachmentStream2=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 5 + 1,"String_Node_Str",attachmentStream2);
          rev.save();
          attachmentStream2.close();
          InputStream attachmentStream3=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 5 + 2,"String_Node_Str",attachmentStream3);
          rev.save();
          attachmentStream3.close();
          InputStream attachmentStream4=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 5 + 3,"String_Node_Str",attachmentStream4);
          rev.save();
          attachmentStream4.close();
          InputStream attachmentStream5=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 5 + 4,"String_Node_Str",attachmentStream5);
          rev.save();
          attachmentStream5.close();
          Map<String,Object> curProperties;
          doc=database.getDocument(id);
          curProperties=doc.getProperties();
          docProperties=new HashMap<String,Object>();
          docProperties.putAll(curProperties);
          docProperties.put("String_Node_Str",(i + 1) * 5);
          doc.putProperties(docProperties);
        }
        Map<String,Object> curProperties;
        doc=database.getDocument(id);
        curProperties=doc.getProperties();
        assertEquals(22,curProperties.size());
        Map<String,Object> attachments=(Map<String,Object>)doc.getCurrentRevision().getProperty("String_Node_Str");
        assertNotNull(attachments);
        assertEquals(100,attachments.size());
      }
 catch (      Exception e) {
        Log.e(Database.TAG,"String_Node_Str",e);
        return false;
      }
      return true;
    }
  }
);
  assertTrue("String_Node_Str",success);
}

Fixed version (ground truth):
/** 
 * attempt to reproduce - https://github.com/couchbase/couchbase-lite-android/issues/328 & - https://github.com/couchbase/couchbase-lite-android/issues/325
 */
public void testSetAttachmentsSequentiallyInTransaction() throws CouchbaseLiteException, IOException {
  boolean success=database.runInTransaction(new TransactionalTask(){
    public boolean run(){
      try {
        Document doc=database.createDocument();
        String id=doc.getId();
        InputStream jsonStream=getAsset("String_Node_Str");
        Map<String,Object> docProperties=null;
        docProperties=Manager.getObjectMapper().readValue(jsonStream,Map.class);
        docProperties.put("String_Node_Str",0);
        doc.putProperties(docProperties);
        jsonStream.close();
        UnsavedRevision rev=null;
        for (int i=0; i < 5; i++) {
          InputStream attachmentStream1=getAsset("String_Node_Str");
          Log.e(Database.TAG,"String_Node_Str" + i);
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 3,"String_Node_Str",attachmentStream1);
          rev.save();
          attachmentStream1.close();
          InputStream attachmentStream2=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 3 + 1,"String_Node_Str",attachmentStream2);
          rev.save();
          attachmentStream2.close();
          InputStream attachmentStream3=getAsset("String_Node_Str");
          doc=database.getDocument(id);
          rev=doc.createRevision();
          rev.setAttachment("String_Node_Str" + i * 3 + 2,"String_Node_Str",attachmentStream3);
          rev.save();
          attachmentStream3.close();
          Map<String,Object> curProperties;
          doc=database.getDocument(id);
          curProperties=doc.getProperties();
          docProperties=new HashMap<String,Object>();
          docProperties.putAll(curProperties);
          docProperties.put("String_Node_Str",(i + 1) * 3);
          doc.putProperties(docProperties);
        }
        Map<String,Object> curProperties;
        doc=database.getDocument(id);
        curProperties=doc.getProperties();
        assertEquals(22,curProperties.size());
        Map<String,Object> attachments=(Map<String,Object>)doc.getCurrentRevision().getProperty("String_Node_Str");
        assertNotNull(attachments);
        assertEquals(15,attachments.size());
      }
 catch (      Exception e) {
        Log.e(Database.TAG,"String_Node_Str",e);
        return false;
      }
      return true;
    }
  }
);
  assertTrue("String_Node_Str",success);
}