Program: 104817
Project: 104817
Buggy source:
private void readCollection(final DBObject dbObject,final MappedField mf,final Object entity,Reference refAnn,EntityCache cache,Mapper mapr){
  Class referenceObjClass=mf.getSubClass();
  Collection references=mf.isSet() ? mapr.getOptions().objectFactory.createSet(mf) : mapr.getOptions().objectFactory.createList(mf);
  if (refAnn.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
    Object dbVal=mf.getDbObjectValue(dbObject);
    if (dbVal != null) {
      references=mapr.proxyFactory.createListProxy(references,referenceObjClass,refAnn.ignoreMissing(),mapr.datastoreProvider);
      ProxiedEntityReferenceList referencesAsProxy=(ProxiedEntityReferenceList)references;
      if (dbVal instanceof List) {
        List<DBRef> refList=(List)dbVal;
        DatastoreImpl dsi=(DatastoreImpl)mapr.datastoreProvider.get();
        List<Key<Object>> keys=dsi.getKeysByRefs(refList);
        if (keys.size() != refList.size()) {
          String msg="String_Node_Str" + mf.getFullName() + "String_Node_Str"+ refList+ "String_Node_Str"+ keys;
          if (!refAnn.ignoreMissing())           throw new MappingException(msg);
 else           log.warning(msg);
        }
        referencesAsProxy.__addAll(keys);
      }
 else {
        DBRef dbRef=(DBRef)dbVal;
        if (!exists(mf.getSubClass(),dbRef,cache,mapr)) {
          String msg="String_Node_Str" + dbRef.toString() + "String_Node_Str"+ mf.getFullName();
          if (!refAnn.ignoreMissing())           throw new MappingException(msg);
 else           log.warning(msg);
        }
 else {
          referencesAsProxy.__add(mapr.refToKey(dbRef));
        }
      }
    }
  }
 else {
    Object dbVal=mf.getDbObjectValue(dbObject);
    if (dbVal != null) {
      if (dbVal instanceof List) {
        List refList=(List)dbVal;
        for (        Object dbRefObj : refList) {
          DBRef dbRef=(DBRef)dbRefObj;
          Key k=mapr.refToKey(dbRef);
          Object cachedEntity=cache.getEntity(k);
          if (cachedEntity != null) {
            references.add(cachedEntity);
          }
 else {
            BasicDBObject refDbObject=(BasicDBObject)dbRef.fetch();
            if (refDbObject == null) {
              if (!refAnn.ignoreMissing()) {
                throw new MappingException("String_Node_Str" + dbRef.toString() + "String_Node_Str"+ mf.getFullName());
              }
            }
 else {
              Object refObj=mapr.getOptions().objectFactory.createInstance(referenceObjClass,refDbObject);
              refObj=mapr.fromDb(refDbObject,refObj,cache);
              references.add(refObj);
              cache.putEntity(k,refObj);
            }
          }
        }
      }
 else {
        DBRef dbRef=(DBRef)dbVal;
        Key k=mapr.refToKey(dbRef);
        Object cachedEntity=cache.getEntity(k);
        if (cachedEntity != null) {
          references.add(cachedEntity);
        }
 else {
          BasicDBObject refDbObject=(BasicDBObject)dbRef.fetch();
          if (refDbObject == null) {
            if (!refAnn.ignoreMissing()) {
              throw new MappingException("String_Node_Str" + dbRef.toString() + "String_Node_Str"+ mf.getFullName());
            }
          }
 else {
            Object newEntity=mapr.getOptions().objectFactory.createInstance(referenceObjClass,refDbObject);
            newEntity=mapr.fromDb(refDbObject,newEntity,cache);
            references.add(newEntity);
          }
        }
      }
    }
  }
  if (mf.getType().isArray()) {
    mf.setFieldValue(entity,ReflectionUtils.convertToArray(mf.getSubClass(),ReflectionUtils.iterToList(references)));
  }
 else {
    mf.setFieldValue(entity,references);
  }
}

Fixed version (ground truth):
private void readCollection(final DBObject dbObject,final MappedField mf,final Object entity,Reference refAnn,EntityCache cache,Mapper mapr){
  Class referenceObjClass=mf.getSubClass();
  Collection references=mf.isSet() ? mapr.getOptions().objectFactory.createSet(mf) : mapr.getOptions().objectFactory.createList(mf);
  if (refAnn.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
    Object dbVal=mf.getDbObjectValue(dbObject);
    if (dbVal != null) {
      references=mapr.proxyFactory.createListProxy(references,referenceObjClass,refAnn.ignoreMissing(),mapr.datastoreProvider);
      ProxiedEntityReferenceList referencesAsProxy=(ProxiedEntityReferenceList)references;
      if (dbVal instanceof List) {
        List<DBRef> refList=(List)dbVal;
        DatastoreImpl dsi=(DatastoreImpl)mapr.datastoreProvider.get();
        List<Key<Object>> keys=dsi.getKeysByRefs(refList);
        if (keys.size() != refList.size()) {
          String msg="String_Node_Str" + mf.getFullName() + "String_Node_Str"+ refList+ "String_Node_Str"+ keys;
          if (!refAnn.ignoreMissing())           throw new MappingException(msg);
 else           log.warning(msg);
        }
        referencesAsProxy.__addAll(keys);
      }
 else {
        DBRef dbRef=(DBRef)dbVal;
        if (!exists(mf.getSubClass(),dbRef,cache,mapr)) {
          String msg="String_Node_Str" + dbRef.toString() + "String_Node_Str"+ mf.getFullName();
          if (!refAnn.ignoreMissing())           throw new MappingException(msg);
 else           log.warning(msg);
        }
 else {
          referencesAsProxy.__add(mapr.refToKey(dbRef));
        }
      }
    }
  }
 else {
    Object dbVal=mf.getDbObjectValue(dbObject);
    if (dbVal != null) {
      if (dbVal instanceof List) {
        List refList=(List)dbVal;
        for (        Object dbRefObj : refList) {
          DBRef dbRef=(DBRef)dbRefObj;
          Object ent=resolveObject(dbRef,mf,cache,mapr);
          if (ent != null)           references.add(ent);
        }
      }
 else {
        DBRef dbRef=(DBRef)dbVal;
        Object ent=resolveObject(dbRef,mf,cache,mapr);
        if (ent != null)         references.add(ent);
      }
    }
  }
  if (mf.getType().isArray()) {
    mf.setFieldValue(entity,ReflectionUtils.convertToArray(mf.getSubClass(),ReflectionUtils.iterToList(references)));
  }
 else {
    mf.setFieldValue(entity,references);
  }
}