Program: 66579
Project: 66579
Buggy source:
/** 
 * buildWorkingCopyCloneFromRow is an alternative to this which is the normal behavior. A row is read from the database, an original is built/refreshed/returned from the shared cache, and the original is registered/conformed/reverted in the UnitOfWork. <p> This default behavior is only safe when the query is executed on a read connection, otherwise uncommitted data might get loaded into the shared cache. <p> Represents the way TopLink has always worked.
 */
protected Object buildWorkingCopyCloneNormally(ObjectBuildingQuery query,AbstractRecord databaseRow,UnitOfWorkImpl unitOfWork,Object primaryKey,ClassDescriptor concreteDescriptor,JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
  CacheKey unitOfWorkCacheKey=unitOfWork.getIdentityMapAccessorInstance().acquireLock(primaryKey,concreteDescriptor.getJavaClass(),concreteDescriptor);
  Object clone=unitOfWorkCacheKey.getObject();
  boolean found=clone != null;
  Object original=null;
  try {
    if (!found || query.shouldRefreshIdentityMapResult() || query.shouldRetrieveBypassCache()|| (concreteDescriptor.hasFetchGroupManager() && concreteDescriptor.getFetchGroupManager().isPartialObject(clone))) {
      AbstractSession session=unitOfWork.getParentIdentityMapSession(query);
      query.setSession(session);
      if (session.isUnitOfWork()) {
        original=buildObjectInUnitOfWork(query,joinManager,databaseRow,(UnitOfWorkImpl)session,primaryKey,concreteDescriptor);
        if (unitOfWork.shouldCascadeCloneToJoinedRelationship()) {
          return query.registerIndividualResult(original,primaryKey,unitOfWork,joinManager,concreteDescriptor);
        }
 else {
          return query.registerIndividualResult(original,primaryKey,unitOfWork,null,concreteDescriptor);
        }
      }
 else {
        CacheKey parentCacheKey=(CacheKey)buildObject(true,query,databaseRow,session,primaryKey,concreteDescriptor,joinManager);
        original=parentCacheKey.getObject();
        if (query.shouldCacheQueryResults()) {
          query.cacheResult(original);
        }
        if (unitOfWork.isClassReadOnly(original.getClass(),concreteDescriptor)) {
          query.recordCloneForPessimisticLocking(original,unitOfWork);
          return original;
        }
        if (!query.isRegisteringResults()) {
          return original;
        }
        if (clone == null) {
          clone=unitOfWork.cloneAndRegisterObject(original,parentCacheKey,unitOfWorkCacheKey,concreteDescriptor);
        }
        if (concreteDescriptor.hasFetchGroupManager()) {
          if (concreteDescriptor.getFetchGroupManager().shouldWriteInto(original,clone)) {
            concreteDescriptor.getFetchGroupManager().writePartialIntoClones(original,clone,unitOfWork);
          }
        }
      }
    }
    query.postRegisterIndividualResult(clone,original,primaryKey,unitOfWork,joinManager,concreteDescriptor);
  }
  finally {
    unitOfWorkCacheKey.release();
    query.setSession(unitOfWork);
  }
  return clone;
}

Fixed version (ground truth):
/** 
 * buildWorkingCopyCloneFromRow is an alternative to this which is the normal behavior. A row is read from the database, an original is built/refreshed/returned from the shared cache, and the original is registered/conformed/reverted in the UnitOfWork. <p> This default behavior is only safe when the query is executed on a read connection, otherwise uncommitted data might get loaded into the shared cache. <p> Represents the way TopLink has always worked.
 */
protected Object buildWorkingCopyCloneNormally(ObjectBuildingQuery query,AbstractRecord databaseRow,UnitOfWorkImpl unitOfWork,Object primaryKey,ClassDescriptor concreteDescriptor,JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
  CacheKey unitOfWorkCacheKey=unitOfWork.getIdentityMapAccessorInstance().acquireLock(primaryKey,concreteDescriptor.getJavaClass(),concreteDescriptor);
  Object clone=unitOfWorkCacheKey.getObject();
  boolean found=clone != null;
  Object original=null;
  try {
    if (!found || query.shouldRefreshIdentityMapResult() || query.shouldCacheQueryResults()|| query.shouldRetrieveBypassCache()|| (concreteDescriptor.hasFetchGroupManager() && concreteDescriptor.getFetchGroupManager().isPartialObject(clone))) {
      AbstractSession session=unitOfWork.getParentIdentityMapSession(query);
      query.setSession(session);
      if (session.isUnitOfWork()) {
        original=buildObjectInUnitOfWork(query,joinManager,databaseRow,(UnitOfWorkImpl)session,primaryKey,concreteDescriptor);
        if (unitOfWork.shouldCascadeCloneToJoinedRelationship()) {
          return query.registerIndividualResult(original,primaryKey,unitOfWork,joinManager,concreteDescriptor);
        }
 else {
          return query.registerIndividualResult(original,primaryKey,unitOfWork,null,concreteDescriptor);
        }
      }
 else {
        CacheKey parentCacheKey=(CacheKey)buildObject(true,query,databaseRow,session,primaryKey,concreteDescriptor,joinManager);
        original=parentCacheKey.getObject();
        if (query.shouldCacheQueryResults()) {
          query.cacheResult(original);
        }
        if (unitOfWork.isClassReadOnly(original.getClass(),concreteDescriptor)) {
          query.recordCloneForPessimisticLocking(original,unitOfWork);
          return original;
        }
        if (!query.isRegisteringResults()) {
          return original;
        }
        if (clone == null) {
          clone=unitOfWork.cloneAndRegisterObject(original,parentCacheKey,unitOfWorkCacheKey,concreteDescriptor);
        }
        if (concreteDescriptor.hasFetchGroupManager()) {
          if (concreteDescriptor.getFetchGroupManager().shouldWriteInto(original,clone)) {
            concreteDescriptor.getFetchGroupManager().writePartialIntoClones(original,clone,unitOfWork);
          }
        }
      }
    }
    query.postRegisterIndividualResult(clone,original,primaryKey,unitOfWork,joinManager,concreteDescriptor);
  }
  finally {
    unitOfWorkCacheKey.release();
    query.setSession(unitOfWork);
  }
  return clone;
}