Program: 67562
Project: 67562
Buggy source:
/** 
 * INTERNAL: Cascade discover and persist new objects during commit.
 */
public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object,Map newObjects,Map unregisteredExistingObjects,Map visitedObjects,UnitOfWorkImpl uow){
  Object cloneAttribute=getAttributeValueFromObject(object);
  if ((cloneAttribute == null) || (!getIndirectionPolicy().objectIsInstantiated(cloneAttribute))) {
    if (cloneAttribute instanceof IndirectCollection) {
      IndirectCollection collection=(IndirectCollection)cloneAttribute;
      if (collection.hasDeferredChanges()) {
        Iterator iterator=collection.getAddedElements().iterator();
        boolean cascade=isCascadePersist();
        while (iterator.hasNext()) {
          Object nextObject=iterator.next();
          if (uow.hasPrivateOwnedObjects()) {
            uow.removePrivateOwnedObject(this,nextObject);
          }
          uow.discoverAndPersistUnregisteredNewObjects(nextObject,cascade,newObjects,unregisteredExistingObjects,visitedObjects);
        }
      }
    }
    return;
  }
  ContainerPolicy containerPolicy=getContainerPolicy();
  Object cloneObjectCollection=getRealCollectionAttributeValueFromObject(object,uow);
  Object iterator=containerPolicy.iteratorFor(cloneObjectCollection);
  boolean cascade=isCascadePersist();
  while (containerPolicy.hasNext(iterator)) {
    Object wrappedObject=containerPolicy.nextEntry(iterator,uow);
    Object nextObject=containerPolicy.unwrapIteratorResult(wrappedObject);
    if (uow.hasPrivateOwnedObjects()) {
      uow.removePrivateOwnedObject(this,nextObject);
    }
    uow.discoverAndPersistUnregisteredNewObjects(nextObject,cascade,newObjects,unregisteredExistingObjects,visitedObjects);
    containerPolicy.cascadeDiscoverAndPersistUnregisteredNewObjects(wrappedObject,newObjects,unregisteredExistingObjects,visitedObjects,uow);
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Cascade discover and persist new objects during commit.
 */
public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object,Map newObjects,Map unregisteredExistingObjects,Map visitedObjects,UnitOfWorkImpl uow){
  Object cloneAttribute=getAttributeValueFromObject(object);
  if ((cloneAttribute == null) || (!getIndirectionPolicy().objectIsInstantiated(cloneAttribute))) {
    if (cloneAttribute instanceof IndirectCollection) {
      IndirectCollection collection=(IndirectCollection)cloneAttribute;
      if (collection.hasDeferredChanges()) {
        Iterator iterator=collection.getAddedElements().iterator();
        boolean cascade=isCascadePersist();
        while (iterator.hasNext()) {
          Object nextObject=iterator.next();
          if (isCandidateForPrivateOwnedRemoval()) {
            uow.removePrivateOwnedObject(this,nextObject);
          }
          uow.discoverAndPersistUnregisteredNewObjects(nextObject,cascade,newObjects,unregisteredExistingObjects,visitedObjects);
        }
      }
    }
    return;
  }
  ContainerPolicy containerPolicy=getContainerPolicy();
  Object cloneObjectCollection=getRealCollectionAttributeValueFromObject(object,uow);
  Object iterator=containerPolicy.iteratorFor(cloneObjectCollection);
  boolean cascade=isCascadePersist();
  while (containerPolicy.hasNext(iterator)) {
    Object wrappedObject=containerPolicy.nextEntry(iterator,uow);
    Object nextObject=containerPolicy.unwrapIteratorResult(wrappedObject);
    if (isCandidateForPrivateOwnedRemoval()) {
      uow.removePrivateOwnedObject(this,nextObject);
    }
    uow.discoverAndPersistUnregisteredNewObjects(nextObject,cascade,newObjects,unregisteredExistingObjects,visitedObjects);
    containerPolicy.cascadeDiscoverAndPersistUnregisteredNewObjects(wrappedObject,newObjects,unregisteredExistingObjects,visitedObjects,uow);
  }
}