Program: 104904
Project: 104904
Buggy source:
void mapReferencesFromDBObject(BasicDBObject dbObject,MappedField mf,Object entity){
  String name=mf.getName();
  Class fieldType=mf.getType();
  try {
    Reference refAnn=mf.getAnnotation(Reference.class);
    if (mf.isMap()) {
      Class referenceObjClass=mf.getSubType();
      Map map=(Map)tryConstructor(HashMap.class,mf.getCTor());
      if (dbObject.containsField(name)) {
        BasicDBObject dbVal=(BasicDBObject)dbObject.get(name);
        for (        Map.Entry entry : dbVal.entrySet()) {
          DBRef dbRef=(DBRef)entry.getValue();
          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=createInstance(referenceObjClass,refDbObject);
            refObj=mapDBObjectToEntity(refDbObject,refObj);
            map.put(entry.getKey(),refObj);
          }
        }
      }
      mf.setFieldValue(entity,map);
    }
 else     if (mf.isMultipleValues()) {
      Class referenceObjClass=mf.getSubType();
      Collection references=(Collection)tryConstructor((!mf.isSet()) ? ArrayList.class : HashSet.class,mf.getCTor());
      if (dbObject.containsField(name)) {
        Object dbVal=dbObject.get(name);
        if (dbVal instanceof List) {
          List refList=(List)dbVal;
          for (          Object dbRefObj : refList) {
            DBRef dbRef=(DBRef)dbRefObj;
            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=createInstance(referenceObjClass,refDbObject);
              refObj=mapDBObjectToEntity(refDbObject,refObj);
              references.add(refObj);
            }
          }
        }
 else {
          DBRef dbRef=(DBRef)dbObject.get(name);
          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=createInstance(referenceObjClass,refDbObject);
            newEntity=mapDBObjectToEntity(refDbObject,newEntity);
            references.add(newEntity);
          }
        }
      }
      mf.setFieldValue(entity,references);
    }
 else {
      Class referenceObjClass=fieldType;
      if (dbObject.containsField(name)) {
        DBRef dbRef=(DBRef)dbObject.get(name);
        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=createInstance(referenceObjClass,refDbObject);
          refObj=mapDBObjectToEntity(refDbObject,refObj);
          mf.setFieldValue(entity,refObj);
        }
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
void mapReferencesFromDBObject(BasicDBObject dbObject,MappedField mf,Object entity){
  String name=mf.getName();
  Class fieldType=mf.getType();
  try {
    Reference refAnn=mf.getAnnotation(Reference.class);
    if (mf.isMap()) {
      Class referenceObjClass=mf.getSubType();
      Map map=(Map)tryConstructor(HashMap.class,mf.getCTor());
      if (dbObject.containsField(name)) {
        BasicDBObject dbVal=(BasicDBObject)dbObject.get(name);
        for (        Map.Entry entry : dbVal.entrySet()) {
          DBRef dbRef=(DBRef)entry.getValue();
          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=createInstance(referenceObjClass,refDbObject);
            refObj=mapDBObjectToEntity(refDbObject,refObj);
            map.put(entry.getKey(),refObj);
          }
        }
      }
      mf.setFieldValue(entity,map);
    }
 else     if (mf.isMultipleValues()) {
      Class referenceObjClass=mf.getSubType();
      Collection references=(Collection)tryConstructor((!mf.isSet()) ? ArrayList.class : HashSet.class,mf.getCTor());
      if (dbObject.containsField(name)) {
        Object dbVal=dbObject.get(name);
        List<DBRef> dbVals=(dbVal instanceof List) ? (List<DBRef>)dbVal : Collections.singletonList((DBRef)dbVal);
        for (        DBRef dbRef : dbVals) {
          BasicDBObject dbRefObj=(BasicDBObject)dbRef.fetch();
          if (dbRefObj == null) {
            if (!refAnn.ignoreMissing())             throw new MappingException("String_Node_Str" + dbRef.toString() + "String_Node_Str"+ mf.getFullName());
          }
 else {
            Object refObj=createInstance(referenceObjClass,dbRefObj);
            refObj=mapDBObjectToEntity(dbRefObj,refObj);
            references.add(refObj);
          }
        }
      }
      if (references.size() > 0)       if (mf.getType().isArray()) {
        Object[] array=convertToArray(mf.getSubType(),references);
        mf.setFieldValue(entity,array);
      }
 else       mf.setFieldValue(entity,references);
    }
 else {
      Class referenceObjClass=fieldType;
      if (dbObject.containsField(name)) {
        DBRef dbRef=(DBRef)dbObject.get(name);
        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=createInstance(referenceObjClass,refDbObject);
          refObj=mapDBObjectToEntity(refDbObject,refObj);
          mf.setFieldValue(entity,refObj);
        }
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}