Program: 104882
Project: 104882
Buggy source:
/** 
 * <p> Converts an entity (POJO) to a DBObject </p>
 */
public DBObject toDBObject(Object entity,final LinkedHashMap<Object,DBObject> involvedObjects){
  entity=ProxyHelper.unwrap(entity);
  BasicDBObject dbObject=new BasicDBObject();
  MappedClass mc=getMappedClass(entity);
  if (mc.getEntityAnnotation() == null || !mc.getEntityAnnotation().noClassnameStored())   dbObject.put(CLASS_NAME_FIELDNAME,entity.getClass().getName());
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PrePersist.class,entity,dbObject,this);
  for (  MappedField mf : mc.getPersistenceFields()) {
    try {
      Class<? extends Annotation> annType=null;
      boolean foundAnnotation=false;
      for (      Class<? extends Annotation> testType : new Class[]{Id.class,Property.class,Embedded.class,Serialized.class,Reference.class})       if (mf.hasAnnotation(testType)) {
        annType=testType;
        foundAnnotation=true;
        break;
      }
      if (Id.class.equals(annType)) {
        Object dbVal=mf.getFieldValue(entity);
        if (dbVal != null)         dbObject.put(ID_KEY,converters.encode(ReflectionUtils.asObjectIdMaybe(dbVal)));
      }
 else       if (Property.class.equals(annType) || Serialized.class.equals(annType) || mf.isTypeMongoCompatible()|| (converters.hasSimpleValueConverter(mf)))       valueMapper.toDBObject(entity,mf,dbObject,opts);
 else       if (Reference.class.equals(annType))       referenceMapper.toDBObject(entity,mf,dbObject,opts);
 else       if (Embedded.class.equals(annType)) {
        embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,opts);
      }
 else {
        logger.fine("String_Node_Str" + mf);
        embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,opts);
      }
    }
 catch (    Exception e) {
      throw new MappingException("String_Node_Str" + mf.getFullName(),e);
    }
  }
  if (involvedObjects != null) {
    involvedObjects.put(entity,dbObject);
  }
  mc.callLifecycleMethods(PreSave.class,entity,dbObject,this);
  return dbObject;
}

Fixed version (ground truth):
/** 
 * <p> Converts an entity (POJO) to a DBObject </p>
 */
public DBObject toDBObject(Object entity,final LinkedHashMap<Object,DBObject> involvedObjects){
  entity=ProxyHelper.unwrap(entity);
  BasicDBObject dbObject=new BasicDBObject();
  MappedClass mc=getMappedClass(entity);
  if (mc.getEntityAnnotation() == null || !mc.getEntityAnnotation().noClassnameStored())   dbObject.put(CLASS_NAME_FIELDNAME,entity.getClass().getName());
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PrePersist.class,entity,dbObject,this);
  for (  MappedField mf : mc.getPersistenceFields()) {
    try {
      Class<? extends Annotation> annType=null;
      for (      Class<? extends Annotation> testType : new Class[]{Id.class,Property.class,Embedded.class,Serialized.class,Reference.class})       if (mf.hasAnnotation(testType)) {
        annType=testType;
        break;
      }
      if (Id.class.equals(annType)) {
        Object idVal=mf.getFieldValue(entity);
        if (idVal != null) {
          if (!mf.isTypeMongoCompatible() && !converters.hasSimpleValueConverter(mf)) {
            embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,opts);
          }
 else {
            Object dbVal=converters.encode(ReflectionUtils.asObjectIdMaybe(idVal));
            dbObject.put(ID_KEY,dbVal);
          }
        }
      }
 else       if (Property.class.equals(annType) || Serialized.class.equals(annType) || mf.isTypeMongoCompatible()|| (converters.hasSimpleValueConverter(mf)))       valueMapper.toDBObject(entity,mf,dbObject,opts);
 else       if (Reference.class.equals(annType))       referenceMapper.toDBObject(entity,mf,dbObject,opts);
 else       if (Embedded.class.equals(annType)) {
        embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,opts);
      }
 else {
        logger.fine("String_Node_Str" + mf);
        embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,opts);
      }
    }
 catch (    Exception e) {
      throw new MappingException("String_Node_Str" + mf.getFullName(),e);
    }
  }
  if (involvedObjects != null) {
    involvedObjects.put(entity,dbObject);
  }
  mc.callLifecycleMethods(PreSave.class,entity,dbObject,this);
  return dbObject;
}