Program: 104698
Project: 104698
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(MappedField mf,MappedClass mc,Object value){
  Object mappedValue=value;
  if ((mf != null && (mf.hasAnnotation(Reference.class) || mf.getType().isAssignableFrom(Key.class) || mf.getType().isAssignableFrom(DBRef.class)|| (value instanceof Iterable && mf.isMultipleValues() && (mf.getSubClass().isAssignableFrom(Key.class) || mf.getSubClass().isAssignableFrom(DBRef.class))))) || (mc != null && mc.getEntityAnnotation() != null)) {
    try {
      if (value instanceof Iterable) {
        ArrayList<DBRef> refs=new ArrayList<DBRef>();
        Iterable it=(Iterable)value;
        for (        Object o : it) {
          Key<?> k=(o instanceof Key) ? (Key<?>)o : getKey(o);
          DBRef dbref=keyToRef(k);
          refs.add(dbref);
        }
        mappedValue=refs;
      }
 else {
        if (value == null)         mappedValue=null;
        Key<?> k=(value instanceof Key) ? (Key<?>)value : getKey(value);
        mappedValue=keyToRef(k);
        if (mappedValue == value)         throw new ValidationException("String_Node_Str");
      }
    }
 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 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(MappedField mf,MappedClass mc,Object value){
  Object mappedValue=value;
  if ((mf != null && (mf.hasAnnotation(Reference.class) || mf.getType().isAssignableFrom(Key.class) || mf.getType().isAssignableFrom(DBRef.class)|| (value instanceof Iterable && mf.isMultipleValues() && (mf.getSubClass().isAssignableFrom(Key.class) || mf.getSubClass().isAssignableFrom(DBRef.class))))) || (mc != null && mc.getEntityAnnotation() != null)) {
    try {
      if (value instanceof Iterable) {
        ArrayList<DBRef> refs=new ArrayList<DBRef>();
        Iterable it=(Iterable)value;
        for (        Object o : it) {
          Key<?> k=(o instanceof Key) ? (Key<?>)o : getKey(o);
          DBRef dbref=keyToRef(k);
          refs.add(dbref);
        }
        mappedValue=refs;
      }
 else {
        if (value == null)         mappedValue=null;
        Key<?> k=(value instanceof Key) ? (Key<?>)value : getKey(value);
        mappedValue=keyToRef(k);
        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 DBObject && !EmbeddedMapper.shouldSaveClassName(value,mappedValue,mf))     ((DBObject)mappedValue).removeField(CLASS_NAME_FIELDNAME);
  }
  return mappedValue;
}