Program: 104910
Project: 104910
Buggy source:
void mapEmbeddedToDBObject(Object entity,MappedField mf,BasicDBObject dbObject){
  String name=mf.getName();
  Object fieldValue=null;
  try {
    fieldValue=mf.getFieldValue(entity);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (mf.isMap()) {
    Map<String,Object> map=(Map<String,Object>)fieldValue;
    if (map != null) {
      BasicDBObject values=new BasicDBObject();
      for (      Map.Entry<String,Object> entry : map.entrySet()) {
        Object entryVal=entry.getValue();
        DBObject convertedVal=toDBObject(entryVal);
        if (mf.getSubType().equals(entryVal.getClass()))         convertedVal.removeField(Mapper.CLASS_NAME_FIELDNAME);
        String strKey=objectToValue(entry.getKey()).toString();
        values.put(strKey,convertedVal);
      }
      if (values.size() > 0)       dbObject.put(name,values);
    }
  }
 else   if (mf.isMultipleValues()) {
    Iterable coll=(Iterable)fieldValue;
    if (coll != null) {
      List values=new ArrayList();
      for (      Object o : coll) {
        DBObject dbObj=toDBObject(o);
        if (mf.getSubType().equals(o.getClass()))         dbObj.removeField(Mapper.CLASS_NAME_FIELDNAME);
        values.add(dbObj);
      }
      if (values.size() > 0)       dbObject.put(name,values);
    }
  }
 else {
    DBObject dbObj=fieldValue == null ? null : toDBObject(fieldValue);
    if (dbObj != null) {
      if (mf.getType().equals(fieldValue.getClass()))       dbObj.removeField(Mapper.CLASS_NAME_FIELDNAME);
      if (dbObj.keySet().size() > 0)       dbObject.put(name,dbObj);
    }
  }
}

Fixed version (ground truth):
void mapEmbeddedToDBObject(Object entity,MappedField mf,BasicDBObject dbObject,LinkedHashMap<Object,DBObject> involvedObjects){
  String name=mf.getName();
  Object fieldValue=null;
  try {
    fieldValue=mf.getFieldValue(entity);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (mf.isMap()) {
    Map<String,Object> map=(Map<String,Object>)fieldValue;
    if (map != null) {
      BasicDBObject values=new BasicDBObject();
      for (      Map.Entry<String,Object> entry : map.entrySet()) {
        Object entryVal=entry.getValue();
        DBObject convertedVal=toDBObject(entryVal,involvedObjects);
        if (mf.getSubType().equals(entryVal.getClass()))         convertedVal.removeField(Mapper.CLASS_NAME_FIELDNAME);
        String strKey=objectToValue(entry.getKey()).toString();
        values.put(strKey,convertedVal);
      }
      if (values.size() > 0)       dbObject.put(name,values);
    }
  }
 else   if (mf.isMultipleValues()) {
    Iterable coll=(Iterable)fieldValue;
    if (coll != null) {
      List values=new ArrayList();
      for (      Object o : coll) {
        DBObject dbObj=toDBObject(o,involvedObjects);
        if (mf.getSubType().equals(o.getClass()))         dbObj.removeField(Mapper.CLASS_NAME_FIELDNAME);
        values.add(dbObj);
      }
      if (values.size() > 0)       dbObject.put(name,values);
    }
  }
 else {
    DBObject dbObj=fieldValue == null ? null : toDBObject(fieldValue,involvedObjects);
    if (dbObj != null) {
      if (mf.getType().equals(fieldValue.getClass()))       dbObj.removeField(Mapper.CLASS_NAME_FIELDNAME);
      if (dbObj.keySet().size() > 0)       dbObject.put(name,dbObj);
    }
  }
}