Program: 63301
Project: 63301
Buggy source:
/** 
 * Merge the changes specified within the changeSet into the cache. The object passed in is the original object from the cache.
 */
protected Object mergeChangesIntoDistributedCache(Object original,ObjectChangeSet changeSet){
  AbstractSession session=this.session;
  Class localClassType=changeSet.getClassType(session);
  ClassDescriptor descriptor=session.getDescriptor(localClassType);
  if (changeSet.getSynchronizationType() == ClassDescriptor.INVALIDATE_CHANGED_OBJECTS) {
    session.getIdentityMapAccessorInstance().invalidateObject(changeSet.getId(),localClassType);
    return original;
  }
  if ((!changeSet.isNew()) && descriptor.usesVersionLocking()) {
    if ((session.getCommandManager() != null) && (session.getCommandManager().getCommandConverter() != null)) {
      changeSet.rebuildWriteLockValueFromUserFormat(descriptor,session);
    }
    int difference=descriptor.getOptimisticLockingPolicy().getVersionDifference(changeSet.getInitialWriteLockValue(),original,changeSet.getId(),session);
    if (difference < 0) {
      session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
      return original;
    }
 else     if (difference > 0) {
      session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
      session.getIdentityMapAccessorInstance().invalidateObject(changeSet.getId(),localClassType);
      return original;
    }
  }
  session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
  if (changeSet.isNew() || (changeSet.getSynchronizationType() != ClassDescriptor.DO_NOT_SEND_CHANGES)) {
    Object primaryKey=changeSet.getId();
    CacheKey cacheKey=changeSet.getActiveCacheKey();
    if (cacheKey == null || !cacheKey.isAcquired()) {
      cacheKey=session.getIdentityMapAccessorInstance().getWriteLockManager().appendLock(primaryKey,original,descriptor,this,session);
    }
    descriptor.getObjectBuilder().mergeChangesIntoObject(original,changeSet,null,this,session,false,false);
    if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy().isStoredInCache()) {
      cacheKey.setWriteLockValue(changeSet.getWriteLockValue());
    }
    cacheKey.setObject(original);
    if (descriptor.getCacheInvalidationPolicy().shouldUpdateReadTimeOnUpdate() || changeSet.isNew()) {
      cacheKey.setReadTime(getSystemTime());
    }
    cacheKey.updateAccess();
  }
  return original;
}

Fixed version (ground truth):
/** 
 * Merge the changes specified within the changeSet into the cache. The object passed in is the original object from the cache.
 */
protected Object mergeChangesIntoDistributedCache(Object original,ObjectChangeSet changeSet){
  AbstractSession session=this.session;
  Class localClassType=changeSet.getClassType(session);
  ClassDescriptor descriptor=session.getDescriptor(localClassType);
  if (changeSet.getSynchronizationType() == ClassDescriptor.INVALIDATE_CHANGED_OBJECTS) {
    session.getIdentityMapAccessorInstance().invalidateObject(changeSet.getId(),localClassType);
    return original;
  }
  if ((!changeSet.isNew()) && descriptor.usesVersionLocking()) {
    if ((session.getCommandManager() != null) && (session.getCommandManager().getCommandConverter() != null)) {
      changeSet.rebuildWriteLockValueFromUserFormat(descriptor,session);
    }
    int difference=descriptor.getOptimisticLockingPolicy().getVersionDifference(changeSet.getInitialWriteLockValue(),original,changeSet.getId(),session);
    if (difference < 0) {
      session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
      return original;
    }
 else     if (difference > 0) {
      session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
      session.getIdentityMapAccessorInstance().invalidateObject(changeSet.getId(),localClassType);
      return original;
    }
  }
  session.log(SessionLog.FINEST,SessionLog.PROPAGATION,"String_Node_Str",changeSet.getClassName(),changeSet.getId());
  if (changeSet.isNew() || (changeSet.getSynchronizationType() != ClassDescriptor.DO_NOT_SEND_CHANGES)) {
    Object primaryKey=changeSet.getId();
    CacheKey cacheKey=changeSet.getActiveCacheKey();
    if (cacheKey == null || !cacheKey.isAcquired()) {
      cacheKey=session.getIdentityMapAccessorInstance().getWriteLockManager().appendLock(primaryKey,original,descriptor,this,session);
    }
    descriptor.getObjectBuilder().mergeChangesIntoObject(original,changeSet,null,this,session,false,false);
    if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy().isStoredInCache()) {
      cacheKey.setWriteLockValue(changeSet.getWriteLockValue());
    }
    if (descriptor.isProtectedIsolation() && changeSet.hasProtectedForeignKeys()) {
      descriptor.getObjectBuilder().cacheForeignKeyValues(changeSet.getProtectedForeignKeys(),cacheKey,session);
    }
    cacheKey.setObject(original);
    if (descriptor.getCacheInvalidationPolicy().shouldUpdateReadTimeOnUpdate() || changeSet.isNew()) {
      cacheKey.setReadTime(getSystemTime());
    }
    cacheKey.updateAccess();
  }
  return original;
}