Program: 63913
Project: 63913
Buggy source:
/** 
 * Update the object. This is used by the unit-of-work update.
 */
public void updateObjectForWriteWithChangeSet(){
  WriteObjectQuery writeQuery=getWriteObjectQuery();
  ObjectChangeSet changeSet=writeQuery.getObjectChangeSet();
  Object object=writeQuery.getObject();
  ClassDescriptor descriptor=getDescriptor();
  DescriptorQueryManager queryManager=descriptor.getQueryManager();
  AbstractSession session=getSession();
  CommitManager commitManager=session.getCommitManager();
  if ((!writeQuery.isUserDefined()) && queryManager.hasUpdateQuery() && isExpressionQueryMechanism()) {
    commitManager.markPreModifyCommitInProgress(object);
    performUserDefinedUpdate();
    return;
  }
  commitManager.markPreModifyCommitInProgress(object);
  DescriptorEventManager eventManager=descriptor.getEventManager();
  if (changeSet.hasChanges()) {
    if (eventManager.hasAnyEventListeners()) {
      DescriptorEvent event=new DescriptorEvent(DescriptorEventManager.PreUpdateWithChangesEvent,writeQuery);
      eventManager.executeEvent(event);
      UnitOfWorkChangeSet uowChangeSet=(UnitOfWorkChangeSet)((UnitOfWorkImpl)session).getUnitOfWorkChangeSet();
      if (!uowChangeSet.isChangeSetFromOutsideUOW() && writeQuery.getObjectChangeSet().shouldRecalculateAfterUpdateEvent()) {
        if (!descriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy()) {
          writeQuery.getObjectChangeSet().clear(false);
        }
        if (descriptor.getObjectChangePolicy().calculateChangesForExistingObject(object,uowChangeSet,((UnitOfWorkImpl)session),descriptor,false) == null) {
          uowChangeSet.getAllChangeSets().remove(writeQuery.getObjectChangeSet());
        }
      }
    }
  }
  if (writeQuery.shouldCascadeParts()) {
    queryManager.preUpdate(writeQuery);
  }
  writeQuery.setModifyRow(descriptor.getObjectBuilder().buildRowForUpdateWithChangeSet(writeQuery));
  Boolean shouldModifyVersionField=changeSet.shouldModifyVersionField();
  if (!getModifyRow().isEmpty() || shouldModifyVersionField != null || changeSet.hasCmpPolicyForcedUpdate()) {
    if (writeQuery.isUserDefined() || writeQuery.isCallQuery()) {
      writeQuery.setModifyRow(descriptor.getObjectBuilder().buildRow(object,session,WriteType.UNDEFINED));
    }
    OptimisticLockingPolicy lockingPolicy=descriptor.getOptimisticLockingPolicy();
    if (lockingPolicy != null) {
      lockingPolicy.addLockValuesToTranslationRow(writeQuery);
      if ((shouldModifyVersionField != null && shouldModifyVersionField) || (shouldModifyVersionField == null && !getModifyRow().isEmpty())) {
        lockingPolicy.updateRowAndObjectForUpdate(writeQuery,object);
      }
 else       if (!shouldModifyVersionField && (lockingPolicy instanceof VersionLockingPolicy)) {
        ((VersionLockingPolicy)lockingPolicy).writeLockValueIntoRow(writeQuery,object);
      }
    }
    if (descriptor.hasSerializedObjectPolicy()) {
      descriptor.getSerializedObjectPolicy().putObjectIntoRow(getModifyRow(),object,session);
    }
    if (eventManager.hasAnyEventListeners()) {
      DescriptorEvent event=new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent,writeQuery);
      event.setRecord(getModifyRow());
      eventManager.executeEvent(event);
    }
    if (QueryMonitor.shouldMonitor()) {
      QueryMonitor.incrementUpdate(getWriteObjectQuery());
    }
    int rowCount=updateObject().intValue();
    if (rowCount < 1) {
      if (session.hasEventManager()) {
        session.getEventManager().noRowsModified(writeQuery,object);
      }
    }
    if (lockingPolicy != null) {
      lockingPolicy.validateUpdate(rowCount,object,writeQuery);
    }
  }
  commitManager.markPostModifyCommitInProgress(object);
  if (writeQuery.shouldCascadeParts()) {
    queryManager.postUpdate(writeQuery);
  }
  if ((descriptor.getHistoryPolicy() != null) && descriptor.getHistoryPolicy().shouldHandleWrites()) {
    descriptor.getHistoryPolicy().postUpdate(writeQuery);
  }
  if (eventManager.hasAnyEventListeners()) {
    eventManager.executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent,writeQuery));
  }
}

Fixed version (ground truth):
/** 
 * Update the object. This is used by the unit-of-work update.
 */
public void updateObjectForWriteWithChangeSet(){
  WriteObjectQuery writeQuery=getWriteObjectQuery();
  ObjectChangeSet changeSet=writeQuery.getObjectChangeSet();
  Object object=writeQuery.getObject();
  ClassDescriptor descriptor=getDescriptor();
  DescriptorQueryManager queryManager=descriptor.getQueryManager();
  AbstractSession session=getSession();
  CommitManager commitManager=session.getCommitManager();
  if ((!writeQuery.isUserDefined()) && queryManager.hasUpdateQuery() && isExpressionQueryMechanism()) {
    commitManager.markPreModifyCommitInProgress(object);
    performUserDefinedUpdate();
    return;
  }
  commitManager.markPreModifyCommitInProgress(object);
  DescriptorEventManager eventManager=descriptor.getEventManager();
  if (changeSet.hasChanges()) {
    if (eventManager.hasAnyEventListeners()) {
      DescriptorEvent event=new DescriptorEvent(DescriptorEventManager.PreUpdateWithChangesEvent,writeQuery);
      eventManager.executeEvent(event);
      UnitOfWorkChangeSet uowChangeSet=(UnitOfWorkChangeSet)((UnitOfWorkImpl)session).getUnitOfWorkChangeSet();
      if (!uowChangeSet.isChangeSetFromOutsideUOW() && writeQuery.getObjectChangeSet().shouldRecalculateAfterUpdateEvent()) {
        if (!descriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy()) {
          writeQuery.getObjectChangeSet().clear(false);
        }
        if (descriptor.getObjectChangePolicy().calculateChangesForExistingObject(object,uowChangeSet,((UnitOfWorkImpl)session),descriptor,false) == null) {
          uowChangeSet.getAllChangeSets().remove(writeQuery.getObjectChangeSet());
        }
      }
    }
  }
  if (writeQuery.shouldCascadeParts()) {
    queryManager.preUpdate(writeQuery);
  }
  writeQuery.setModifyRow(descriptor.getObjectBuilder().buildRowForUpdateWithChangeSet(writeQuery));
  Boolean shouldModifyVersionField=changeSet.shouldModifyVersionField();
  if (!getModifyRow().isEmpty() || shouldModifyVersionField != null || changeSet.hasCmpPolicyForcedUpdate()) {
    if (writeQuery.isUserDefined() || writeQuery.isCallQuery()) {
      writeQuery.setModifyRow(descriptor.getObjectBuilder().buildRow(object,session,WriteType.UNDEFINED));
    }
    OptimisticLockingPolicy lockingPolicy=descriptor.getOptimisticLockingPolicy();
    if (lockingPolicy != null) {
      lockingPolicy.addLockValuesToTranslationRow(writeQuery);
      boolean existingOptimisticLock=false;
      if (session instanceof RepeatableWriteUnitOfWork) {
        RepeatableWriteUnitOfWork uow=(RepeatableWriteUnitOfWork)session;
        if (uow.getOptimisticReadLockObjects().get(object) != null && uow.getCumulativeUOWChangeSet() != null && uow.getCumulativeUOWChangeSet().getObjectChangeSetForClone(object) != null) {
          existingOptimisticLock=true;
        }
      }
      if (!existingOptimisticLock) {
        if ((shouldModifyVersionField != null && shouldModifyVersionField) || !getModifyRow().isEmpty()) {
          lockingPolicy.updateRowAndObjectForUpdate(writeQuery,object);
        }
 else         if (!shouldModifyVersionField && (lockingPolicy instanceof VersionLockingPolicy)) {
          ((VersionLockingPolicy)lockingPolicy).writeLockValueIntoRow(writeQuery,object);
        }
      }
    }
    if (descriptor.hasSerializedObjectPolicy()) {
      descriptor.getSerializedObjectPolicy().putObjectIntoRow(getModifyRow(),object,session);
    }
    if (eventManager.hasAnyEventListeners()) {
      DescriptorEvent event=new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent,writeQuery);
      event.setRecord(getModifyRow());
      eventManager.executeEvent(event);
    }
    if (QueryMonitor.shouldMonitor()) {
      QueryMonitor.incrementUpdate(getWriteObjectQuery());
    }
    int rowCount=updateObject().intValue();
    if (rowCount < 1) {
      if (session.hasEventManager()) {
        session.getEventManager().noRowsModified(writeQuery,object);
      }
    }
    if (lockingPolicy != null) {
      lockingPolicy.validateUpdate(rowCount,object,writeQuery);
    }
  }
  commitManager.markPostModifyCommitInProgress(object);
  if (writeQuery.shouldCascadeParts()) {
    queryManager.postUpdate(writeQuery);
  }
  if ((descriptor.getHistoryPolicy() != null) && descriptor.getHistoryPolicy().shouldHandleWrites()) {
    descriptor.getHistoryPolicy().postUpdate(writeQuery);
  }
  if (eventManager.hasAnyEventListeners()) {
    eventManager.executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent,writeQuery));
  }
}