Program: 104662
Project: 104662
Buggy source:
/** 
 * <p> Converts a java object to a mongo-compatible object (possibly a DBObject for complex mappings). Very similar to   {@link Mapper#toDBObject} </p> <p> Used (mainly) by query/update operations </p>
 */
public Object toMongoObject(final MappedField mf,final MappedClass mc,final Object value){
  Object mappedValue=value;
  if (isAssignable(mf,value) || isEntity(mc)) {
    try {
      if (value instanceof Iterable) {
        MappedClass mapped=getMappedClass(mf.getSubClass());
        if (mapped != null && (Key.class.isAssignableFrom(mapped.getClazz()) || mapped.getEntityAnnotation() != null)) {
          mappedValue=getDBRefs((Iterable)value);
        }
 else {
          mappedValue=toMongoObject(value,false);
        }
      }
 else {
        final Key<?> key=(value instanceof Key) ? (Key<?>)value : getKey(value);
        if (key == null) {
          mappedValue=toMongoObject(value,false);
        }
 else {
          mappedValue=keyToRef(key);
          if (mappedValue == value) {
            throw new ValidationException("String_Node_Str" + value);
          }
        }
      }
    }
 catch (    Exception e) {
      LOG.error("String_Node_Str" + value + "String_Node_Str",e);
      mappedValue=toMongoObject(value,false);
    }
  }
 else   if (mf != null && mf.hasAnnotation(Serialized.class)) {
    try {
      mappedValue=Serializer.serialize(value,!mf.getAnnotation(Serialized.class).disableCompression());
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
  }
 else   if (value instanceof DBObject) {
    mappedValue=value;
  }
 else {
    mappedValue=toMongoObject(value,EmbeddedMapper.shouldSaveClassName(value,mappedValue,mf));
    if (mappedValue instanceof BasicDBList) {
      final BasicDBList list=(BasicDBList)mappedValue;
      if (list.size() != 0) {
        if (!EmbeddedMapper.shouldSaveClassName(extractFirstElement(value),list.get(0),mf)) {
          for (          Object o : list) {
            if (o instanceof DBObject) {
              ((DBObject)o).removeField(CLASS_NAME_FIELDNAME);
            }
          }
        }
      }
    }
 else     if (mappedValue instanceof DBObject && !EmbeddedMapper.shouldSaveClassName(value,mappedValue,mf)) {
      ((DBObject)mappedValue).removeField(CLASS_NAME_FIELDNAME);
    }
  }
  return mappedValue;
}

Fixed version (ground truth):
/** 
 * <p> Converts a java object to a mongo-compatible object (possibly a DBObject for complex mappings). Very similar to   {@link Mapper#toDBObject} </p> <p> Used (mainly) by query/update operations </p>
 */
public Object toMongoObject(final MappedField mf,final MappedClass mc,final Object value){
  Object mappedValue=value;
  if (isAssignable(mf,value) || isEntity(mc)) {
    try {
      if (value instanceof Iterable) {
        MappedClass mapped=getMappedClass(mf.getSubClass());
        if (mapped != null && (Key.class.isAssignableFrom(mapped.getClazz()) || mapped.getEntityAnnotation() != null)) {
          mappedValue=getDBRefs((Iterable)value);
        }
 else {
          if (mf.getSubClass() == null) {
            mappedValue=getDBRefs((Iterable)value);
          }
 else {
            mappedValue=toMongoObject(value,false);
          }
        }
      }
 else {
        final Key<?> key=(value instanceof Key) ? (Key<?>)value : getKey(value);
        if (key == null) {
          mappedValue=toMongoObject(value,false);
        }
 else {
          mappedValue=keyToRef(key);
          if (mappedValue == value) {
            throw new ValidationException("String_Node_Str" + value);
          }
        }
      }
    }
 catch (    Exception e) {
      LOG.error("String_Node_Str" + value + "String_Node_Str",e);
      mappedValue=toMongoObject(value,false);
    }
  }
 else   if (mf != null && mf.hasAnnotation(Serialized.class)) {
    try {
      mappedValue=Serializer.serialize(value,!mf.getAnnotation(Serialized.class).disableCompression());
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
  }
 else   if (value instanceof DBObject) {
    mappedValue=value;
  }
 else {
    mappedValue=toMongoObject(value,EmbeddedMapper.shouldSaveClassName(value,mappedValue,mf));
    if (mappedValue instanceof BasicDBList) {
      final BasicDBList list=(BasicDBList)mappedValue;
      if (list.size() != 0) {
        if (!EmbeddedMapper.shouldSaveClassName(extractFirstElement(value),list.get(0),mf)) {
          for (          Object o : list) {
            if (o instanceof DBObject) {
              ((DBObject)o).removeField(CLASS_NAME_FIELDNAME);
            }
          }
        }
      }
    }
 else     if (mappedValue instanceof DBObject && !EmbeddedMapper.shouldSaveClassName(value,mappedValue,mf)) {
      ((DBObject)mappedValue).removeField(CLASS_NAME_FIELDNAME);
    }
  }
  return mappedValue;
}