Program: 64520
Project: 64520
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 (!getModifyRow().isEmpty() || shouldModifyVersionField.booleanValue()) {
        lockingPolicy.updateRowAndObjectForUpdate(writeQuery,object);
      }
 else       if (!shouldModifyVersionField.booleanValue() && (lockingPolicy instanceof VersionLockingPolicy)) {
        ((VersionLockingPolicy)lockingPolicy).writeLockValueIntoRow(writeQuery,object);
      }
    }
    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);
      if ((shouldModifyVersionField != null && shouldModifyVersionField) || (shouldModifyVersionField == null && !getModifyRow().isEmpty())) {
        lockingPolicy.updateRowAndObjectForUpdate(writeQuery,object);
      }
 else       if (!shouldModifyVersionField && (lockingPolicy instanceof VersionLockingPolicy)) {
        ((VersionLockingPolicy)lockingPolicy).writeLockValueIntoRow(writeQuery,object);
      }
    }
    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));
  }
}