Program: 67527
Project: 67527
Buggy source:
/** 
 * INTERNAL: When merging from a clone when the cache cannot be guaranteed the object must be first read if it is existing and not in the cache. Otherwise no changes will be detected as the original state is missing.
 */
protected Object registerObjectForMergeCloneIntoWorkingCopy(Object clone){
  UnitOfWorkImpl unitOfWork=(UnitOfWorkImpl)getSession();
  ClassDescriptor descriptor=unitOfWork.getDescriptor(clone.getClass());
  Vector primaryKey=descriptor.getObjectBuilder().extractPrimaryKeyFromObject(clone,unitOfWork);
  Object objectFromCache=unitOfWork.getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey,descriptor.getJavaClass(),false,descriptor);
  if (objectFromCache == null) {
    objectFromCache=unitOfWork.checkIfAlreadyRegistered(clone,descriptor);
  }
  if (objectFromCache != null) {
    if (unitOfWork.isObjectDeleted(objectFromCache)) {
      if (shouldMergeCloneIntoWorkingCopy() || shouldMergeCloneWithReferencesIntoWorkingCopy()) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{clone}));
      }
    }
    return objectFromCache;
  }
  org.eclipse.persistence.queries.DoesExistQuery existQuery=descriptor.getQueryManager().getDoesExistQuery();
  if (existQuery.shouldCheckCacheForDoesExist()) {
    Object registeredObject=unitOfWork.internalRegisterObject(clone,descriptor);
    if (unitOfWork.hasNewObjects() && unitOfWork.getNewObjectsOriginalToClone().containsKey(clone)) {
      mergedNewObjects.put(registeredObject,registeredObject);
    }
    return registeredObject;
  }
  Boolean doesExist=(Boolean)existQuery.checkEarlyReturn(clone,primaryKey,unitOfWork,null);
  if (doesExist == Boolean.FALSE) {
    Object registeredObject=unitOfWork.internalRegisterObject(clone,descriptor);
    mergedNewObjects.put(registeredObject,registeredObject);
    return registeredObject;
  }
  Object object=unitOfWork.readObject(clone);
  if (object == null) {
    object=unitOfWork.cloneAndRegisterNewObject(clone);
    mergedNewObjects.put(object,object);
  }
  return object;
}

Fixed version (ground truth):
/** 
 * INTERNAL: When merging from a clone when the cache cannot be guaranteed the object must be first read if it is existing and not in the cache. Otherwise no changes will be detected as the original state is missing.
 */
protected Object registerObjectForMergeCloneIntoWorkingCopy(Object clone){
  UnitOfWorkImpl unitOfWork=(UnitOfWorkImpl)getSession();
  ClassDescriptor descriptor=unitOfWork.getDescriptor(clone.getClass());
  Vector primaryKey=descriptor.getObjectBuilder().extractPrimaryKeyFromObject(clone,unitOfWork);
  Object objectFromCache=unitOfWork.getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey,descriptor.getJavaClass(),false,descriptor);
  if (objectFromCache == null) {
    objectFromCache=unitOfWork.checkIfAlreadyRegistered(clone,descriptor);
  }
  if (objectFromCache != null) {
    if (unitOfWork.isObjectDeleted(objectFromCache)) {
      if (shouldMergeCloneIntoWorkingCopy() || shouldMergeCloneWithReferencesIntoWorkingCopy()) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{clone}));
      }
    }
    return objectFromCache;
  }
  org.eclipse.persistence.queries.DoesExistQuery existQuery=descriptor.getQueryManager().getDoesExistQuery();
  if (existQuery.shouldCheckCacheForDoesExist()) {
    if (descriptor.usesVersionLocking()) {
      VersionLockingPolicy policy=(VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
      Object baseValue=policy.getBaseValue();
      Object objectLockValue=policy.getWriteLockValue(clone,primaryKey,unitOfWork);
      if (policy.isNewerVersion(objectLockValue,baseValue)) {
        throw OptimisticLockException.objectChangedSinceLastMerge(clone);
      }
    }
    Object registeredObject=unitOfWork.internalRegisterObject(clone,descriptor);
    if (unitOfWork.hasNewObjects() && unitOfWork.getNewObjectsOriginalToClone().containsKey(clone)) {
      mergedNewObjects.put(registeredObject,registeredObject);
    }
    return registeredObject;
  }
  Boolean doesExist=(Boolean)existQuery.checkEarlyReturn(clone,primaryKey,unitOfWork,null);
  if (doesExist == Boolean.FALSE) {
    if (descriptor.usesVersionLocking()) {
      VersionLockingPolicy policy=(VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
      Object baseValue=policy.getBaseValue();
      Object objectLockValue=policy.getWriteLockValue(clone,primaryKey,unitOfWork);
      if (policy.isNewerVersion(objectLockValue,baseValue)) {
        throw OptimisticLockException.objectChangedSinceLastMerge(clone);
      }
    }
    Object registeredObject=unitOfWork.internalRegisterObject(clone,descriptor);
    mergedNewObjects.put(registeredObject,registeredObject);
    return registeredObject;
  }
  Object object=unitOfWork.readObject(clone);
  if (object == null) {
    if (descriptor.usesVersionLocking()) {
      VersionLockingPolicy policy=(VersionLockingPolicy)descriptor.getOptimisticLockingPolicy();
      Object baseValue=policy.getBaseValue();
      Object objectLockValue=policy.getWriteLockValue(clone,primaryKey,unitOfWork);
      if (policy.isNewerVersion(objectLockValue,baseValue)) {
        throw OptimisticLockException.objectChangedSinceLastMerge(clone);
      }
    }
    object=unitOfWork.cloneAndRegisterNewObject(clone);
    mergedNewObjects.put(object,object);
  }
  return object;
}