Program: 104835
Project: 104835
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 Object javaObj){
  if (javaObj == null) {
    return null;
  }
  Class origClass=javaObj.getClass();
  Object newObj=converters.encode(origClass,javaObj);
  if (newObj == null) {
    logger.warning("String_Node_Str" + javaObj + "String_Node_Str");
    return newObj;
  }
  Class type=newObj.getClass();
  boolean bSameType=origClass.equals(type);
  if (!bSameType)   return newObj;
 else {
    boolean isSingleValue=true;
    boolean isMap=false;
    Class subType=null;
    if (type.isArray() || ReflectionUtils.implementsAnyInterface(type,Iterable.class,Map.class)) {
      isSingleValue=false;
      isMap=ReflectionUtils.implementsInterface(type,Map.class);
      subType=(type.isArray()) ? type.getComponentType() : ReflectionUtils.getParameterizedClass(type,(isMap) ? 1 : 0);
    }
    if (isSingleValue && !ReflectionUtils.isPropertyType(type)) {
      DBObject dbObj=toDBObject(newObj);
      dbObj.removeField(CLASS_NAME_FIELDNAME);
      return dbObj;
    }
 else     if (newObj instanceof DBObject) {
      return newObj;
    }
 else     if (isMap) {
      if (ReflectionUtils.isPropertyType(subType))       return toDBObject(newObj);
 else {
        HashMap m=new HashMap();
        for (        Map.Entry e : (Iterable<Map.Entry>)((Map)newObj).entrySet())         m.put(e.getKey(),toMongoObject(e.getValue()));
        return toDBObject(m);
      }
    }
 else     if (!isSingleValue && !ReflectionUtils.isPropertyType(subType)) {
      ArrayList<Object> vals=new ArrayList<Object>();
      if (type.isArray())       for (      Object obj : (Object[])newObj)       vals.add(toMongoObject(obj));
 else       for (      Object obj : (Iterable)newObj)       vals.add(toMongoObject(obj));
      return vals;
    }
 else {
      return newObj;
    }
  }
}

Fixed version (ground truth):
public Object toMongoObject(final Object javaObj,boolean includeClassName){
  if (javaObj == null) {
    return null;
  }
  Class origClass=javaObj.getClass();
  Object newObj=converters.encode(origClass,javaObj);
  if (newObj == null) {
    logger.warning("String_Node_Str" + javaObj + "String_Node_Str");
    return newObj;
  }
  Class type=newObj.getClass();
  boolean bSameType=origClass.equals(type);
  if (!bSameType)   return newObj;
 else {
    boolean isSingleValue=true;
    boolean isMap=false;
    Class subType=null;
    if (type.isArray() || ReflectionUtils.implementsAnyInterface(type,Iterable.class,Map.class)) {
      isSingleValue=false;
      isMap=ReflectionUtils.implementsInterface(type,Map.class);
      subType=(type.isArray()) ? type.getComponentType() : ReflectionUtils.getParameterizedClass(type,(isMap) ? 1 : 0);
    }
    if (isSingleValue && !ReflectionUtils.isPropertyType(type)) {
      DBObject dbObj=toDBObject(newObj);
      if (!includeClassName)       dbObj.removeField(CLASS_NAME_FIELDNAME);
      return dbObj;
    }
 else     if (newObj instanceof DBObject) {
      return newObj;
    }
 else     if (isMap) {
      if (ReflectionUtils.isPropertyType(subType))       return toDBObject(newObj);
 else {
        HashMap m=new HashMap();
        for (        Map.Entry e : (Iterable<Map.Entry>)((Map)newObj).entrySet())         m.put(e.getKey(),toMongoObject(e.getValue(),includeClassName));
        return toDBObject(m);
      }
    }
 else     if (!isSingleValue && !ReflectionUtils.isPropertyType(subType)) {
      ArrayList<Object> vals=new ArrayList<Object>();
      if (type.isArray())       for (      Object obj : (Object[])newObj)       vals.add(toMongoObject(obj,includeClassName));
 else       for (      Object obj : (Iterable)newObj)       vals.add(toMongoObject(obj,includeClassName));
      return vals;
    }
 else {
      return newObj;
    }
  }
}