Program: 66424
Project: 66424
Buggy source:
/** 
 * INTERNAL: Update private owned part.
 */
protected void postUpdateWithChangeSet(WriteObjectQuery writeQuery) throws DatabaseException {
  ObjectChangeSet changeSet=writeQuery.getObjectChangeSet();
  DirectCollectionChangeRecord changeRecord=(DirectCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName());
  if (changeRecord == null) {
    return;
  }
  for (int index=0; index < getReferenceKeyFields().size(); index++) {
    DatabaseField referenceKey=getReferenceKeyFields().get(index);
    DatabaseField sourceKey=getSourceKeyFields().get(index);
    Object sourceKeyValue=writeQuery.getTranslationRow().get(sourceKey);
    writeQuery.getTranslationRow().put(referenceKey,sourceKeyValue);
  }
  for (Iterator iterator=changeRecord.getRemoveObjectMap().keySet().iterator(); iterator.hasNext(); ) {
    Object object=iterator.next();
    AbstractRecord thisRow=writeQuery.getTranslationRow().clone();
    Object value=getFieldValue(object,writeQuery.getSession());
    thisRow.add(getDirectField(),value);
    Object[] event=new Object[3];
    event[0]=Delete;
    event[1]=getDeleteQuery();
    event[2]=thisRow;
    writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
    Integer count=(Integer)changeRecord.getCommitAddMap().get(object);
    if (count != null) {
      for (int counter=count.intValue(); counter > 0; --counter) {
        thisRow=writeQuery.getTranslationRow().clone();
        thisRow.add(getDirectField(),value);
        event=new Object[3];
        event[0]=Insert;
        event[1]=getInsertQuery();
        event[2]=thisRow;
        writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
      }
    }
  }
  for (Iterator iterator=changeRecord.getAddObjectMap().keySet().iterator(); iterator.hasNext(); ) {
    Object object=iterator.next();
    Integer count=(Integer)changeRecord.getAddObjectMap().get(object);
    for (int counter=count.intValue(); counter > 0; --counter) {
      AbstractRecord thisRow=writeQuery.getTranslationRow().clone();
      Object value=object;
      if (getValueConverter() != null) {
        value=getValueConverter().convertObjectValueToDataValue(value,writeQuery.getSession());
      }
      thisRow.add(getDirectField(),value);
      Object[] event=new Object[3];
      event[0]=Insert;
      event[1]=getInsertQuery();
      event[2]=thisRow;
      writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
    }
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Update private owned part.
 */
protected void postUpdateWithChangeSet(WriteObjectQuery writeQuery) throws DatabaseException {
  ObjectChangeSet changeSet=writeQuery.getObjectChangeSet();
  DirectCollectionChangeRecord changeRecord=(DirectCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName());
  if (changeRecord == null) {
    return;
  }
  for (int index=0; index < getReferenceKeyFields().size(); index++) {
    DatabaseField referenceKey=getReferenceKeyFields().get(index);
    DatabaseField sourceKey=getSourceKeyFields().get(index);
    Object sourceKeyValue=writeQuery.getTranslationRow().get(sourceKey);
    writeQuery.getTranslationRow().put(referenceKey,sourceKeyValue);
  }
  for (Iterator iterator=changeRecord.getRemoveObjectMap().keySet().iterator(); iterator.hasNext(); ) {
    Object object=iterator.next();
    AbstractRecord thisRow=writeQuery.getTranslationRow().clone();
    Object value=getFieldValue(object,writeQuery.getSession());
    Object[] event=new Object[3];
    event[0]=Delete;
    if (value == null) {
      event[1]=getDeleteNullQuery();
    }
 else {
      thisRow.add(getDirectField(),value);
      event[1]=getDeleteQuery();
    }
    event[2]=thisRow;
    writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
    Integer count=(Integer)changeRecord.getCommitAddMap().get(object);
    if (count != null) {
      for (int counter=count.intValue(); counter > 0; --counter) {
        thisRow=writeQuery.getTranslationRow().clone();
        thisRow.add(getDirectField(),value);
        event=new Object[3];
        event[0]=Insert;
        event[1]=getInsertQuery();
        event[2]=thisRow;
        writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
      }
    }
  }
  for (Iterator iterator=changeRecord.getAddObjectMap().keySet().iterator(); iterator.hasNext(); ) {
    Object object=iterator.next();
    Integer count=(Integer)changeRecord.getAddObjectMap().get(object);
    for (int counter=count.intValue(); counter > 0; --counter) {
      AbstractRecord thisRow=writeQuery.getTranslationRow().clone();
      Object value=object;
      if (getValueConverter() != null) {
        value=getValueConverter().convertObjectValueToDataValue(value,writeQuery.getSession());
      }
      thisRow.add(getDirectField(),value);
      Object[] event=new Object[3];
      event[0]=Insert;
      event[1]=getInsertQuery();
      event[2]=thisRow;
      writeQuery.getSession().getCommitManager().addDataModificationEvent(this,event);
    }
  }
}