nus-yam/ex-repair huggingface dataset:
Program: 104627
Project: 104627
Buggy source:
@Test @Ignore public void shouldFindAllByIdQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  String documentId2=randomNumeric(5);
  SampleEntity sampleEntity2=new SampleEntity();
  sampleEntity2.setId(documentId2);
  sampleEntity2.setMessage("String_Node_Str");
  repository.save(sampleEntity2);
  Iterable<SampleEntity> sampleEntities=repository.findAll(Arrays.asList(documentId,documentId2));
  assertNotNull("String_Node_Str",sampleEntities);
}

Fixed version (ground truth):
@Test @Ignore public void shouldFindAllByIdQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  String documentId2=randomNumeric(5);
  SampleEntity sampleEntity2=new SampleEntity();
  sampleEntity2.setId(documentId2);
  sampleEntity2.setMessage("String_Node_Str");
  sampleEntity2.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity2);
  Iterable<SampleEntity> sampleEntities=repository.findAll(Arrays.asList(documentId,documentId2));
  assertNotNull("String_Node_Str",sampleEntities);
}
Program: 104628
Project: 104628
Buggy source:
@Test public void shouldSearchDocumentsGivenSearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  SearchQuery query=new SearchQuery();
  query.setElasticsearchQuery(termQuery("String_Node_Str","String_Node_Str"));
  Page<SampleEntity> page=repository.search(query);
  assertThat(page,is(notNullValue()));
  assertThat(page.getNumberOfElements(),is(greaterThanOrEqualTo(1)));
}

Fixed version (ground truth):
@Test public void shouldSearchDocumentsGivenSearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  SearchQuery query=new SearchQuery();
  query.setElasticsearchQuery(termQuery("String_Node_Str","String_Node_Str"));
  Page<SampleEntity> page=repository.search(query);
  assertThat(page,is(notNullValue()));
  assertThat(page.getNumberOfElements(),is(greaterThanOrEqualTo(1)));
}
Program: 104629
Project: 104629
Buggy source:
@Test public void shouldSaveDocument(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(notNullValue()));
}

Fixed version (ground truth):
@Test public void shouldSaveDocument(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(notNullValue()));
}
Program: 104630
Project: 104630
Buggy source:
@Test public void shouldDeleteDocument(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  repository.delete(documentId);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(nullValue()));
}

Fixed version (ground truth):
@Test public void shouldDeleteDocument(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  repository.delete(documentId);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(nullValue()));
}
Program: 104631
Project: 104631
Buggy source:
@Test public void shouldSearchDocumentsGivenElasticsearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  Page<SampleEntity> page=repository.search(termQuery("String_Node_Str","String_Node_Str"),new PageRequest(0,50));
  assertThat(page,is(notNullValue()));
  assertThat(page.getNumberOfElements(),is(greaterThanOrEqualTo(1)));
}

Fixed version (ground truth):
@Test public void shouldSearchDocumentsGivenElasticsearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  Page<SampleEntity> page=repository.search(termQuery("String_Node_Str","String_Node_Str"),new PageRequest(0,50));
  assertThat(page,is(notNullValue()));
  assertThat(page.getNumberOfElements(),is(greaterThanOrEqualTo(1)));
}
Program: 104632
Project: 104632
Buggy source:
@Test public void shouldFindDocumentById(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(notNullValue()));
  assertThat(sampleEntity,is((equalTo(sampleEntity))));
}

Fixed version (ground truth):
@Test public void shouldFindDocumentById(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  SampleEntity entityFromElasticSearch=repository.findOne(documentId);
  assertThat(entityFromElasticSearch,is(notNullValue()));
  assertThat(sampleEntity,is((equalTo(sampleEntity))));
}
Program: 104633
Project: 104633
Buggy source:
@Test public void shouldReturnIterableEntities(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity1=new SampleEntity();
  sampleEntity1.setId(documentId);
  sampleEntity1.setMessage("String_Node_Str");
  sampleEntity1.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity1);
  String documentId2=randomNumeric(5);
  SampleEntity sampleEntity2=new SampleEntity();
  sampleEntity2.setId(documentId2);
  sampleEntity2.setMessage("String_Node_Str");
  sampleEntity2.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity2);
  Iterable<SampleEntity> sampleEntities=repository.search(fieldQuery("String_Node_Str",documentId));
  assertNotNull("String_Node_Str",sampleEntities);
}

Fixed version (ground truth):
@Test public void shouldReturnIterableEntities(){
  String documentId1=randomNumeric(5);
  SampleEntity sampleEntity1=new SampleEntity();
  sampleEntity1.setId(documentId1);
  sampleEntity1.setMessage("String_Node_Str");
  sampleEntity1.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity1);
  String documentId2=randomNumeric(5);
  SampleEntity sampleEntity2=new SampleEntity();
  sampleEntity2.setId(documentId2);
  sampleEntity2.setMessage("String_Node_Str");
  sampleEntity2.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity2);
  Iterable<SampleEntity> sampleEntities=repository.search(fieldQuery("String_Node_Str",documentId1));
  assertNotNull("String_Node_Str",sampleEntities);
}
Program: 104634
Project: 104634
Buggy source:
@Test public void shouldReturnCountOfDocuments(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  Long count=repository.count();
  assertThat(count,is(greaterThanOrEqualTo(1L)));
}

Fixed version (ground truth):
@Test public void shouldReturnCountOfDocuments(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  Long count=repository.count();
  assertThat(count,is(greaterThanOrEqualTo(1L)));
}
Program: 104635
Project: 104635
Buggy source:
@Test public void shouldReturnResultsForGivenSearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  SearchQuery searchQuery=new SearchQuery();
  searchQuery.setElasticsearchQuery(fieldQuery("String_Node_Str",documentId));
  Page<SampleEntity> sampleEntities=repository.search(searchQuery);
  assertThat(sampleEntities.getTotalElements(),equalTo(1L));
}

Fixed version (ground truth):
@Test public void shouldReturnResultsForGivenSearchQuery(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  SearchQuery searchQuery=new SearchQuery();
  searchQuery.setElasticsearchQuery(fieldQuery("String_Node_Str",documentId));
  Page<SampleEntity> sampleEntities=repository.search(searchQuery);
  assertThat(sampleEntities.getTotalElements(),equalTo(1L));
}
Program: 104636
Project: 104636
Buggy source:
@Test public void shouldDeleteEntity(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  repository.delete(sampleEntity);
  SearchQuery searchQuery=new SearchQuery();
  searchQuery.setElasticsearchQuery(fieldQuery("String_Node_Str",documentId));
  Page<SampleEntity> sampleEntities=repository.search(searchQuery);
  assertThat(sampleEntities.getTotalElements(),equalTo(0L));
}

Fixed version (ground truth):
@Test public void shouldDeleteEntity(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  repository.delete(sampleEntity);
  SearchQuery searchQuery=new SearchQuery();
  searchQuery.setElasticsearchQuery(fieldQuery("String_Node_Str",documentId));
  Page<SampleEntity> sampleEntities=repository.search(searchQuery);
  assertThat(sampleEntities.getTotalElements(),equalTo(0L));
}
Program: 104637
Project: 104637
Buggy source:
@Test public void shouldReturnTrueGivenDocumentWithIdExists(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  repository.save(sampleEntity);
  boolean exist=repository.exists(documentId);
  assertEquals(exist,true);
}

Fixed version (ground truth):
@Test public void shouldReturnTrueGivenDocumentWithIdExists(){
  String documentId=randomNumeric(5);
  SampleEntity sampleEntity=new SampleEntity();
  sampleEntity.setId(documentId);
  sampleEntity.setMessage("String_Node_Str");
  sampleEntity.setVersion(System.currentTimeMillis());
  repository.save(sampleEntity);
  boolean exist=repository.exists(documentId);
  assertEquals(exist,true);
}
Program: 104638
Project: 104638
Buggy source:
@Override public Long getVersion(T entity){
  ElasticsearchPersistentProperty versionProperty=entityMetadata.getIdProperty();
  try {
    if (versionProperty != null) {
      return (Long)BeanWrapper.create(entity,null).getProperty(versionProperty);
    }
  }
 catch (  Exception e) {
    logger.debug("String_Node_Str",e);
  }
  return null;
}

Fixed version (ground truth):
@Override public Long getVersion(T entity){
  ElasticsearchPersistentProperty versionProperty=entityMetadata.getVersionProperty();
  try {
    if (versionProperty != null) {
      return (Long)BeanWrapper.create(entity,null).getProperty(versionProperty);
    }
  }
 catch (  Exception e) {
    logger.debug("String_Node_Str",e);
  }
  return null;
}
Program: 104639
Project: 104639
Buggy source:
@Override public Long getVersion(T entity){
  ElasticsearchPersistentProperty versionProperty=entityMetadata.getVersionProperty();
  try {
    if (versionProperty != null) {
      return (Long)BeanWrapper.create(entity,null).getProperty(versionProperty);
    }
  }
 catch (  Exception e) {
    logger.debug("String_Node_Str",e);
  }
  return null;
}

Fixed version (ground truth):
@Override public Long getVersion(T entity){
  ElasticsearchPersistentProperty versionProperty=entityMetadata.getVersionProperty();
  try {
    if (versionProperty != null) {
      return (Long)BeanWrapper.create(entity,null).getProperty(versionProperty);
    }
  }
 catch (  Exception e) {
    throw new IllegalStateException("String_Node_Str",e);
  }
  return null;
}
Program: 104640
Project: 104640
Buggy source:
private ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz){
  return elasticsearchConverter.getMappingContext().getPersistentEntity(clazz);
}

Fixed version (ground truth):
private ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz){
  Assert.isTrue(clazz.isAnnotationPresent(Document.class),"String_Node_Str" + clazz.getSimpleName() + "String_Node_Str");
  return elasticsearchConverter.getMappingContext().getPersistentEntity(clazz);
}
Program: 104641
Project: 104641
Buggy source:
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation){
  super(typeInformation);
  this.context=new StandardEvaluationContext();
  Class<T> clazz=typeInformation.getType();
  Assert.isTrue(clazz.isAnnotationPresent(Document.class),clazz.getSimpleName() + "String_Node_Str");
  Document document=clazz.getAnnotation(Document.class);
  Assert.hasText(document.indexName(),"String_Node_Str");
  this.indexName=typeInformation.getType().getAnnotation(Document.class).indexName();
  this.indexType=hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
}

Fixed version (ground truth):
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation){
  super(typeInformation);
  this.context=new StandardEvaluationContext();
  Class<T> clazz=typeInformation.getType();
  if (clazz.isAnnotationPresent(Document.class)) {
    Document document=clazz.getAnnotation(Document.class);
    Assert.hasText(document.indexName(),"String_Node_Str");
    this.indexName=typeInformation.getType().getAnnotation(Document.class).indexName();
    this.indexType=hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
  }
}
Program: 104642
Project: 104642
Buggy source:
@SuppressWarnings("String_Node_Str") private void readMap(final Datastore datastore,final Mapper mapper,final Object entity,final EntityCache cache,final MappedField mf,final DBObject dbObject){
  final Map map=mapper.getOptions().getObjectFactory().createMap(mf);
  final DBObject dbObj=(DBObject)mf.getDbObjectValue(dbObject);
  final EphemeralMappedField ephemeralMappedField=isMapOrCollection(mf) ? new EphemeralMappedField((ParameterizedType)mf.getSubType(),mf,mapper) : null;
  new IterHelper<Object,Object>().loopMap(dbObj,new MapIterCallback<Object,Object>(){
    @Override public void eval(    final Object k,    final Object val){
      Object newEntity=null;
      if (val != null) {
        if (mapper.getConverters().hasSimpleValueConverter(mf) || mapper.getConverters().hasSimpleValueConverter(mf.getSubClass())) {
          newEntity=mapper.getConverters().decode(mf.getSubClass(),val,mf);
        }
 else {
          if (val instanceof DBObject) {
            newEntity=readMapOrCollectionOrEntity(datastore,mapper,cache,mf,ephemeralMappedField,(DBObject)val);
          }
 else {
            newEntity=val;
          }
        }
      }
      final Object objKey=mapper.getConverters().decode(mf.getMapKeyClass(),k,mf);
      map.put(objKey,newEntity);
    }
  }
);
  if (!map.isEmpty() || mapper.getOptions().isStoreEmpties()) {
    mf.setFieldValue(entity,map);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") private void readMap(final Datastore datastore,final Mapper mapper,final Object entity,final EntityCache cache,final MappedField mf,final DBObject dbObject){
  final DBObject dbObj=(DBObject)mf.getDbObjectValue(dbObject);
  if (dbObj != null) {
    final Map map=mapper.getOptions().getObjectFactory().createMap(mf);
    final EphemeralMappedField ephemeralMappedField=isMapOrCollection(mf) ? new EphemeralMappedField((ParameterizedType)mf.getSubType(),mf,mapper) : null;
    new IterHelper<Object,Object>().loopMap(dbObj,new MapIterCallback<Object,Object>(){
      @Override public void eval(      final Object k,      final Object val){
        Object newEntity=null;
        if (val != null) {
          if (mapper.getConverters().hasSimpleValueConverter(mf) || mapper.getConverters().hasSimpleValueConverter(mf.getSubClass())) {
            newEntity=mapper.getConverters().decode(mf.getSubClass(),val,mf);
          }
 else {
            if (val instanceof DBObject) {
              newEntity=readMapOrCollectionOrEntity(datastore,mapper,cache,mf,ephemeralMappedField,(DBObject)val);
            }
 else {
              newEntity=val;
            }
          }
        }
        final Object objKey=mapper.getConverters().decode(mf.getMapKeyClass(),k,mf);
        map.put(objKey,newEntity);
      }
    }
);
    if (!map.isEmpty() || mapper.getOptions().isStoreEmpties()) {
      mf.setFieldValue(entity,map);
    }
  }
}
Program: 104644
Project: 104644
Buggy source:
public static boolean shouldSaveClassName(final Object rawVal,final Object convertedVal,final MappedField mf){
  if (rawVal == null || mf == null) {
    return true;
  }
  if (mf.isSingleValue()) {
    return !(mf.getType().equals(rawVal.getClass()) && !(convertedVal instanceof BasicDBList));
  }
  return !(convertedVal != null && convertedVal instanceof DBObject && !mf.getSubClass().isInterface() && !Modifier.isAbstract(mf.getSubClass().getModifiers()) && mf.getSubClass().equals(rawVal.getClass()));
}

Fixed version (ground truth):
static boolean shouldSaveClassName(final Object rawVal,final Object convertedVal,final MappedField mf){
  if (rawVal == null || mf == null) {
    return true;
  }
  if (mf.isSingleValue()) {
    return !(mf.getType().equals(rawVal.getClass()) && !(convertedVal instanceof BasicDBList));
  }
  return !(convertedVal != null && convertedVal instanceof DBObject && !mf.getSubClass().isInterface() && !Modifier.isAbstract(mf.getSubClass().getModifiers()) && mf.getSubClass().equals(rawVal.getClass()));
}
Program: 104645
Project: 104645
Buggy source:
public Map<Integer,String> getLinkedHashMap(){
  return linkedHashMap;
}

Fixed version (ground truth):
private Map<Integer,String> getLinkedHashMap(){
  return linkedHashMap;
}
Program: 104646
Project: 104646
Buggy source:
@Test public void testKeyOrdering(){
  getMorphia().map(LinkedHashMapTestEntity.class);
  final LinkedHashMapTestEntity expectedEntity=new LinkedHashMapTestEntity();
  for (int i=100; i >= 0; i--) {
    expectedEntity.getLinkedHashMap().put(i,"String_Node_Str" + i);
  }
  getDs().save(expectedEntity);
  LinkedHashMapTestEntity storedEntity=getDs().find(LinkedHashMapTestEntity.class).get();
  Assert.assertNotNull(storedEntity);
  Assert.assertEquals(new ArrayList<Integer>(expectedEntity.getLinkedHashMap().keySet()),new ArrayList<Integer>(storedEntity.getLinkedHashMap().keySet()));
}

Fixed version (ground truth):
@Test public void testKeyOrdering(){
  getMorphia().map(LinkedHashMapTestEntity.class);
  final LinkedHashMapTestEntity expectedEntity=new LinkedHashMapTestEntity();
  for (int i=100; i >= 0; i--) {
    expectedEntity.getLinkedHashMap().put(i,"String_Node_Str" + i);
  }
  getDs().save(expectedEntity);
  LinkedHashMapTestEntity storedEntity=getDs().find(LinkedHashMapTestEntity.class).get();
  Assert.assertNotNull(storedEntity);
  Assert.assertEquals(expectedEntity.getLinkedHashMap(),storedEntity.getLinkedHashMap());
}
Program: 104647
Project: 104647
Buggy source:
private void empties(){
  Datastore ds=getDs();
  ds.delete(ds.createQuery(Employee.class));
  Employee employee=new Employee();
  HashMap<String,Byte> byteMap=new HashMap<String,Byte>();
  byteMap.put("String_Node_Str",(byte)1);
  employee.setByteMap(byteMap);
  ds.save(employee);
  Employee loaded=ds.createQuery(Employee.class).get();
  assertEquals(Byte.valueOf((byte)1),loaded.getByteMap().get("String_Node_Str"));
  assertNull(loaded.getFloatMap());
}

Fixed version (ground truth):
private void empties(){
  Datastore ds=getDs();
  ds.delete(ds.createQuery(Employee.class));
  Employee employee=new Employee();
  HashMap<String,Byte> byteMap=new HashMap<String,Byte>();
  byteMap.put("String_Node_Str",(byte)1);
  employee.byteMap=byteMap;
  ds.save(employee);
  Employee loaded=ds.createQuery(Employee.class).get();
  assertEquals(Byte.valueOf((byte)1),loaded.byteMap.get("String_Node_Str"));
  assertNull(loaded.floatMap);
}
Program: 104648
Project: 104648
Buggy source:
/** 
 * @return the projections for the group
 */
public Projection[] getProjections(){
  return projections;
}

Fixed version (ground truth):
/** 
 * @return the projections for the group
 */
public List<Projection> getProjections(){
  return projections != null ? new ArrayList<Projection>(projections) : null;
}
Program: 104649
Project: 104649
Buggy source:
/** 
 * Create a group of Groups for use as an ID
 * @param fields the Groups to group
 * @return the Group
 */
public static List<Group> id(final Group... fields){
  return Arrays.asList(fields);
}

Fixed version (ground truth):
/** 
 * Create a group of Groups for use as an ID
 * @param fields the Groups to group
 * @return the Group
 */
public static List<Group> id(final Group... fields){
  return asList(fields);
}
Program: 104650
Project: 104650
Buggy source:
@Override @SuppressWarnings("String_Node_Str") public Object decode(final Class targetClass,final Object fromDBObject,final MappedField mf){
  if (mf == null || fromDBObject == null) {
    return fromDBObject;
  }
  final Class subtypeDest=mf.getSubClass();
  final Collection values=createNewCollection(mf);
  if (fromDBObject.getClass().isArray()) {
    for (    final Object o : (Object[])fromDBObject) {
      values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : o.getClass(),o,mf));
    }
  }
 else   if (fromDBObject instanceof Iterable) {
    for (    final Object o : (Iterable)fromDBObject) {
      if (o instanceof DBObject) {
        final MappedField mappedField=mf.getTypeParameters().get(0);
        if (mappedField instanceof EphemeralMappedField) {
          final EphemeralMappedField field=(EphemeralMappedField)getMapper().fromDb((DBObject)o,mappedField,new DefaultEntityCache());
          values.add(field.getValue());
        }
      }
 else {
        values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : o.getClass(),o,mf));
      }
    }
  }
 else {
    values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : fromDBObject.getClass(),fromDBObject,mf));
  }
  if (mf.getType().isArray()) {
    return ReflectionUtils.convertToArray(subtypeDest,(List)values);
  }
 else {
    return values;
  }
}

Fixed version (ground truth):
@Override @SuppressWarnings("String_Node_Str") public Object decode(final Class targetClass,final Object fromDBObject,final MappedField mf){
  if (mf == null || fromDBObject == null) {
    return fromDBObject;
  }
  final Class subtypeDest=mf.getSubClass();
  final Collection values=createNewCollection(mf);
  if (fromDBObject.getClass().isArray()) {
    for (    final Object o : (Object[])fromDBObject) {
      values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : o.getClass(),o,mf));
    }
  }
 else   if (fromDBObject instanceof Iterable) {
    for (    final Object o : (Iterable)fromDBObject) {
      if (o instanceof DBObject) {
        final List<MappedField> typeParameters=mf.getTypeParameters();
        if (!typeParameters.isEmpty()) {
          final MappedField mappedField=typeParameters.get(0);
          if (mappedField instanceof EphemeralMappedField) {
            final EphemeralMappedField field=(EphemeralMappedField)getMapper().fromDb((DBObject)o,mappedField,new DefaultEntityCache());
            values.add(field.getValue());
          }
        }
 else {
          values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : o.getClass(),o,mf));
        }
      }
 else {
        values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : o.getClass(),o,mf));
      }
    }
  }
 else {
    values.add(getMapper().getConverters().decode((subtypeDest != null) ? subtypeDest : fromDBObject.getClass(),fromDBObject,mf));
  }
  if (mf.getType().isArray()) {
    return ReflectionUtils.convertToArray(subtypeDest,(List)values);
  }
 else {
    return values;
  }
}
Program: 104651
Project: 104651
Buggy source:
@Test public void testTwoDimensionalArrayMapping() throws Exception {
  getMorphia().map(ContainsTwoDimensionalArray.class);
  final ContainsTwoDimensionalArray entity=new ContainsTwoDimensionalArray();
  entity.oneDimArray="String_Node_Str".getBytes();
  entity.twoDimArray=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  final Key<ContainsTwoDimensionalArray> savedKey=getDs().save(entity);
  final ContainsTwoDimensionalArray loaded=getDs().get(ContainsTwoDimensionalArray.class,entity.id);
  Assert.assertNotNull(loaded.id);
  Assert.assertNotNull(loaded.oneDimArray);
  Assert.assertNotNull(loaded.twoDimArray);
  compare(entity.oneDimArray,loaded.oneDimArray);
  compare(entity.twoDimArray[0],loaded.twoDimArray[0]);
  compare(entity.twoDimArray[1],loaded.twoDimArray[1]);
}

Fixed version (ground truth):
@Test public void testTwoDimensionalArrayMapping() throws Exception {
  getMorphia().map(ContainsTwoDimensionalArray.class);
  final ContainsTwoDimensionalArray entity=new ContainsTwoDimensionalArray();
  entity.oneDimArray="String_Node_Str".getBytes();
  entity.twoDimArray=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  getDs().save(entity);
  final ContainsTwoDimensionalArray loaded=getDs().get(ContainsTwoDimensionalArray.class,entity.id);
  Assert.assertNotNull(loaded.id);
  Assert.assertNotNull(loaded.oneDimArray);
  Assert.assertNotNull(loaded.twoDimArray);
  compare(entity.oneDimArray,loaded.oneDimArray);
  compare(entity.twoDimArray[0],loaded.twoDimArray[0]);
  compare(entity.twoDimArray[1],loaded.twoDimArray[1]);
}
Program: 104652
Project: 104652
Buggy source:
/** 
 * Returns the parameterized type in the given position
 * @param c     the class to examine
 * @param index the position of the type to return
 * @return the type
 */
public static Class getParameterizedClass(final Class c,final int index){
  final TypeVariable[] typeVars=c.getTypeParameters();
  if (typeVars.length > 0) {
    final TypeVariable typeVariable=typeVars[index];
    final Type[] bounds=typeVariable.getBounds();
    final Type type=bounds[0];
    if (type instanceof Class) {
      return (Class)type;
    }
 else {
      return null;
    }
  }
 else {
    final Type superclass=c.getGenericSuperclass();
    if (superclass instanceof ParameterizedType) {
      final Type[] actualTypeArguments=((ParameterizedType)superclass).getActualTypeArguments();
      return actualTypeArguments.length > index ? (Class<?>)actualTypeArguments[index] : null;
    }
 else     if (!Object.class.equals(superclass)) {
      return getParameterizedClass((Class)superclass);
    }
 else {
      return null;
    }
  }
}

Fixed version (ground truth):
/** 
 * Returns the parameterized type in the given position
 * @param c     the class to examine
 * @param index the position of the type to return
 * @return the type
 */
public static Class getParameterizedClass(final Class c,final int index){
  final TypeVariable[] typeVars=c.getTypeParameters();
  if (typeVars.length > 0) {
    final TypeVariable typeVariable=typeVars[index];
    final Type[] bounds=typeVariable.getBounds();
    final Type type=bounds[0];
    if (type instanceof Class) {
      return (Class)type;
    }
 else {
      return null;
    }
  }
 else {
    Type superclass=c.getGenericSuperclass();
    if (superclass == null && c.isInterface()) {
      Type[] interfaces=c.getGenericInterfaces();
      if (interfaces.length > 0) {
        superclass=interfaces[index];
      }
    }
    if (superclass instanceof ParameterizedType) {
      final Type[] actualTypeArguments=((ParameterizedType)superclass).getActualTypeArguments();
      return actualTypeArguments.length > index ? (Class<?>)actualTypeArguments[index] : null;
    }
 else     if (!Object.class.equals(superclass)) {
      return getParameterizedClass((Class)superclass);
    }
 else {
      return null;
    }
  }
}
Program: 104654
Project: 104654
Buggy source:
private Object readMapOrCollectionOrEntity(final DBObject dbObj,final MappedField mf,final EntityCache cache,final Mapper mapper,MapOrCollectionMF mapOrCollectionMF){
  if (mapOrCollectionMF != null) {
    mapper.fromDb(dbObj,mapOrCollectionMF,cache);
    return mapOrCollectionMF.getValue();
  }
 else {
    final Object newEntity=mapper.getOptions().getObjectFactory().createInstance(mapper,mf,dbObj);
    return mapper.fromDb(dbObj,newEntity,cache);
  }
}

Fixed version (ground truth):
private Object readMapOrCollectionOrEntity(final DBObject dbObj,final MappedField mf,final EntityCache cache,final Mapper mapper,final MapOrCollectionMF mapOrCollectionMF){
  if (mapOrCollectionMF != null) {
    mapper.fromDb(dbObj,mapOrCollectionMF,cache);
    return mapOrCollectionMF.getValue();
  }
 else {
    final Object newEntity=mapper.getOptions().getObjectFactory().createInstance(mapper,mf,dbObj);
    return mapper.fromDb(dbObj,newEntity,cache);
  }
}
Program: 104655
Project: 104655
Buggy source:
private boolean isMapOrCollection(MappedField mf){
  return Map.class.isAssignableFrom(mf.getSubClass()) || Iterable.class.isAssignableFrom(mf.getSubClass());
}

Fixed version (ground truth):
private static boolean isMapOrCollection(final MappedField mf){
  return Map.class.isAssignableFrom(mf.getSubClass()) || Iterable.class.isAssignableFrom(mf.getSubClass());
}
Program: 104656
Project: 104656
Buggy source:
public void setMeta(Map<String,String> meta){
  this.meta=meta;
}

Fixed version (ground truth):
public void setMeta(final Map<String,String> meta){
  this.meta=meta;
}
Program: 104657
Project: 104657
Buggy source:
public void setValues(Map<String,List<Value>> values){
  this.values=values;
}

Fixed version (ground truth):
public void setValues(final Map<String,List<Value>> values){
  this.values=values;
}
Program: 104658
Project: 104658
Buggy source:
public void setId(ObjectId id){
  this.id=id;
}

Fixed version (ground truth):
public void setId(final ObjectId id){
  this.id=id;
}
Program: 104659
Project: 104659
Buggy source:
public void setRaw(String raw){
  this.raw=raw;
}

Fixed version (ground truth):
public void setRaw(final String raw){
  this.raw=raw;
}
Program: 104660
Project: 104660
Buggy source:
/** 
 * Add MappedClass to internal cache, possibly validating first.
 */
private MappedClass addMappedClass(final MappedClass mc,final boolean validate){
  if (validate) {
    mc.validate();
  }
  final Converters c=(Converters)mc.getAnnotation(Converters.class);
  if (c != null) {
    for (    final Class<? extends TypeConverter> clazz : c.value()) {
      if (!getConverters().isRegistered(clazz)) {
        getConverters().addConverter(clazz);
      }
    }
  }
  mappedClasses.put(mc.getClazz().getName(),mc);
  Set<MappedClass> mcs=mappedClassesByCollection.get(mc.getCollectionName());
  if (mcs == null) {
    mcs=new CopyOnWriteArraySet<MappedClass>();
    final Set<MappedClass> temp=mappedClassesByCollection.putIfAbsent(mc.getCollectionName(),mcs);
    if (temp != null) {
      mcs=temp;
    }
  }
  mcs.add(mc);
  return mc;
}

Fixed version (ground truth):
/** 
 * Add MappedClass to internal cache, possibly validating first.
 */
private MappedClass addMappedClass(final MappedClass mc,final boolean validate){
  if (validate) {
    mc.validate();
  }
  final List<Annotation> convertersList=mc.getAnnotations(Converters.class);
  if (convertersList != null) {
    for (    Annotation a : convertersList) {
      final Converters c=(Converters)a;
      if (c != null) {
        for (        final Class<? extends TypeConverter> clazz : c.value()) {
          if (!getConverters().isRegistered(clazz)) {
            getConverters().addConverter(clazz);
          }
        }
      }
    }
  }
  mappedClasses.put(mc.getClazz().getName(),mc);
  Set<MappedClass> mcs=mappedClassesByCollection.get(mc.getCollectionName());
  if (mcs == null) {
    mcs=new CopyOnWriteArraySet<MappedClass>();
    final Set<MappedClass> temp=mappedClassesByCollection.putIfAbsent(mc.getCollectionName(),mcs);
    if (temp != null) {
      mcs=temp;
    }
  }
  mcs.add(mc);
  return mc;
}
Program: 104661
Project: 104661
Buggy source:
public static <T>Class<?> getTypeArgument(final Class<? extends T> clazz,final TypeVariable<? extends GenericDeclaration> tv){
  final Map<Type,Type> resolvedTypes=new HashMap<Type,Type>();
  Type type=clazz;
  while (!getClass(type).equals(Object.class)) {
    if (type instanceof Class) {
      type=((Class)type).getGenericSuperclass();
    }
 else {
      final ParameterizedType parameterizedType=(ParameterizedType)type;
      final Class<?> rawType=(Class)parameterizedType.getRawType();
      final Type[] actualTypeArguments=parameterizedType.getActualTypeArguments();
      final TypeVariable<?>[] typeParameters=rawType.getTypeParameters();
      for (int i=0; i < actualTypeArguments.length; i++) {
        if (typeParameters[i].equals(tv)) {
          final Class cls=getClass(actualTypeArguments[i]);
          if (cls != null) {
            return cls;
          }
          return getClass(resolvedTypes.get(actualTypeArguments[i]));
        }
        resolvedTypes.put(typeParameters[i],actualTypeArguments[i]);
      }
      if (!rawType.equals(Object.class)) {
        type=rawType.getGenericSuperclass();
      }
    }
  }
  return null;
}

Fixed version (ground truth):
public static <T>Class<?> getTypeArgument(final Class<? extends T> clazz,final TypeVariable<? extends GenericDeclaration> tv){
  final Map<Type,Type> resolvedTypes=new HashMap<Type,Type>();
  Type type=clazz;
  while (!getClass(type).equals(Object.class)) {
    if (type instanceof Class) {
      type=((Class)type).getGenericSuperclass();
    }
 else {
      final ParameterizedType parameterizedType=(ParameterizedType)type;
      final Class<?> rawType=(Class)parameterizedType.getRawType();
      final Type[] actualTypeArguments=parameterizedType.getActualTypeArguments();
      final TypeVariable<?>[] typeParameters=rawType.getTypeParameters();
      for (int i=0; i < actualTypeArguments.length; i++) {
        if (typeParameters[i].equals(tv)) {
          final Class cls=getClass(actualTypeArguments[i]);
          if (cls != null) {
            return cls;
          }
          Type typeToTest=resolvedTypes.get(actualTypeArguments[i]);
          while (typeToTest != null) {
            final Class classToTest=getClass(typeToTest);
            if (classToTest != null) {
              return classToTest;
            }
            typeToTest=resolvedTypes.get(typeToTest);
          }
        }
        resolvedTypes.put(typeParameters[i],actualTypeArguments[i]);
      }
      if (!rawType.equals(Object.class)) {
        type=rawType.getGenericSuperclass();
      }
    }
  }
  return null;
}
Program: 104663
Project: 104663
Buggy source:
@Override public int hashCode(){
  return id.hashCode();
}

Fixed version (ground truth):
@Override public int hashCode(){
  return id != null ? id.hashCode() : 0;
}
Program: 104664
Project: 104664
Buggy source:
@Override public boolean equals(final Object obj){
  if (obj == null || obj.getClass() != Ref.class) {
    return false;
  }
  Ref other=(Ref)obj;
  return id.equals(other.id);
}

Fixed version (ground truth):
@Override public boolean equals(final Object o){
  if (this == o) {
    return true;
  }
  if (!(o instanceof Ref)) {
    return false;
  }
  final Ref ref=(Ref)o;
  if (id != null ? !id.equals(ref.id) : ref.id != null) {
    return false;
  }
  return true;
}
Program: 104665
Project: 104665
Buggy source:
protected void cleanup(){
  super.cleanup();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
}

Fixed version (ground truth):
protected void cleanup(){
  super.cleanup();
  DB db=getDb();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
  db.getCollection("String_Node_Str").drop();
}
Program: 104666
Project: 104666
Buggy source:
@Test public void testEmbedded(){
  AdvancedDatastore ads=((AdvancedDatastore)ds);
  ads.save("String_Node_Str",new B(new BB("String_Node_Str")));
  assertEquals(1,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndexes("String_Node_Str",B.class);
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
}

Fixed version (ground truth):
@Test public void testEmbedded(){
  AdvancedDatastore ads=getAds();
  DB db=getDb();
  ads.save("String_Node_Str",new B(new BB("String_Node_Str")));
  assertEquals(1,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndexes("String_Node_Str",B.class);
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
}
Program: 104667
Project: 104667
Buggy source:
/** 
 * Test that indexes created on one collection do not affect other collections.
 */
@Test public void testA(){
  ads.ensureIndexes("String_Node_Str",A.class);
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  ads.ensureIndexes("String_Node_Str",A.class);
  assertEquals(4,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndexes();
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  assertEquals(4,db.getCollection("String_Node_Str").getIndexInfo().size());
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
}

Fixed version (ground truth):
/** 
 * Test that indexes created on one collection do not affect other collections.
 */
@Test public void testA(){
  AdvancedDatastore ads=getAds();
  DB db=getDb();
  ads.ensureIndexes("String_Node_Str",A.class);
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  ads.ensureIndexes("String_Node_Str",A.class);
  assertEquals(4,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndex("String_Node_Str",A.class,"String_Node_Str");
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  ads.ensureIndexes();
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
  assertEquals(4,db.getCollection("String_Node_Str").getIndexInfo().size());
  assertEquals(2,db.getCollection("String_Node_Str").getIndexInfo().size());
}
Program: 104669
Project: 104669
Buggy source:
@Test public void testInQueryByKey() throws Exception {
  final HasRefs hr=new HasRefs();
  List<Key<ReferencedEntity>> refs=new ArrayList<Key<ReferencedEntity>>();
  for (int x=0; x < 10; x++) {
    final ReferencedEntity re=new ReferencedEntity("String_Node_Str" + x);
    getDs().save(re);
    refs.add(new Key<QueryInForKeyTest.ReferencedEntity>(ReferencedEntity.class.getName(),re.getId()));
  }
  hr.ref=refs.get(0);
  getDs().save(hr);
  Query<HasRefs> query=getDs().createQuery(HasRefs.class).field("String_Node_Str").in(refs);
  final List<HasRefs> res=query.asList();
  Assert.assertEquals(1,res.size());
}

Fixed version (ground truth):
@Test public void testInQueryByKey() throws Exception {
  final HasRefs hr=new HasRefs();
  List<Key<ReferencedEntity>> refs=new ArrayList<Key<ReferencedEntity>>();
  for (int x=0; x < 10; x++) {
    final ReferencedEntity re=new ReferencedEntity("String_Node_Str" + x);
    getDs().save(re);
    refs.add(new Key<QueryInForKeyTest.ReferencedEntity>(ReferencedEntity.class.getName(),re.getId()));
  }
  hr.ref=refs.get(0);
  getDs().save(hr);
  Query<HasRefs> query=getDs().createQuery(HasRefs.class).field("String_Node_Str").in(refs);
  try {
    final List<HasRefs> res=query.asList();
    Assert.assertEquals(1,res.size());
  }
 catch (  MongoException e) {
    LOG.debug("String_Node_Str" + query);
    throw e;
  }
}
Program: 104670
Project: 104670
Buggy source:
@Test @Ignore("String_Node_Str" + "String_Node_Str") public void testInQuery() throws Exception {
  final HasRefs hr=new HasRefs();
  for (int x=0; x < 10; x++) {
    final ReferencedEntity re=new ReferencedEntity("String_Node_Str" + x);
    hr.refs.add(re);
  }
  getDs().save(hr.refs);
  getDs().save(hr);
  Query<HasRefs> query=getDs().createQuery(HasRefs.class).field("String_Node_Str").in(hr.refs.subList(1,3));
  final List<HasRefs> res=query.asList();
  Assert.assertEquals(1,res.size());
}

Fixed version (ground truth):
@Test public void testInQuery() throws Exception {
  final HasRefs hr=new HasRefs();
  for (int x=0; x < 10; x++) {
    final ReferencedEntity re=new ReferencedEntity("String_Node_Str" + x);
    hr.refs.add(re);
  }
  getDs().save(hr.refs);
  getDs().save(hr);
  Query<HasRefs> query=getDs().createQuery(HasRefs.class).field("String_Node_Str").in(hr.refs.subList(1,3));
  final List<HasRefs> res=query.asList();
  Assert.assertEquals(1,res.size());
}
Program: 104671
Project: 104671
Buggy source:
public void addTo(final DBObject obj){
  if (joinMethod == CriteriaJoin.AND) {
    Map<String,Integer> fields=new HashMap<String,Integer>();
    for (    final Criteria child : children) {
      String field=child.getFieldName();
      if (null != field) {
        if (fields.containsKey(field))         fields.put(field,fields.get(field) + 1);
 else         fields.put(field,1);
      }
    }
    List<Criteria> ands=new ArrayList<Criteria>();
    for (    Criteria child : this.children) {
      String field=child.getFieldName();
      if (null != field || fields.get(field) <= 1) {
        child.addTo(obj);
      }
 else {
        ands.add(child);
      }
    }
    if (ands.size() > 0) {
      final BasicDBList and=new BasicDBList();
      for (      final Criteria child : ands) {
        final BasicDBObject container=new BasicDBObject();
        child.addTo(container);
        and.add(container);
      }
      obj.put("String_Node_Str",and);
    }
  }
 else   if (joinMethod == CriteriaJoin.OR) {
    final BasicDBList or=new BasicDBList();
    for (    final Criteria child : children) {
      final BasicDBObject container=new BasicDBObject();
      child.addTo(container);
      or.add(container);
    }
    obj.put("String_Node_Str",or);
  }
}

Fixed version (ground truth):
public void addTo(final DBObject obj){
  if (joinMethod == CriteriaJoin.AND) {
    final Set<String> fields=new HashSet<String>();
    int nonNullFieldNames=0;
    for (    final Criteria child : children) {
      if (null != child.getFieldName()) {
        fields.add(child.getFieldName());
        nonNullFieldNames++;
      }
    }
    if (fields.size() < nonNullFieldNames) {
      final BasicDBList and=new BasicDBList();
      for (      final Criteria child : children) {
        final BasicDBObject container=new BasicDBObject();
        child.addTo(container);
        and.add(container);
      }
      obj.put("String_Node_Str",and);
    }
 else {
      for (      final Criteria child : children) {
        child.addTo(obj);
      }
    }
  }
 else   if (joinMethod == CriteriaJoin.OR) {
    final BasicDBList or=new BasicDBList();
    for (    final Criteria child : children) {
      final BasicDBObject container=new BasicDBObject();
      child.addTo(container);
      or.add(container);
    }
    obj.put("String_Node_Str",or);
  }
}
Program: 104672
Project: 104672
Buggy source:
public void addTo(final DBObject obj){
  if (joinMethod == CriteriaJoin.AND) {
    final Set<String> fields=new HashSet<String>();
    int nonNullFieldNames=0;
    for (    final Criteria child : children) {
      if (null != child.getFieldName()) {
        fields.add(child.getFieldName());
        nonNullFieldNames++;
      }
    }
    if (fields.size() < nonNullFieldNames) {
      final BasicDBList and=new BasicDBList();
      for (      final Criteria child : children) {
        final BasicDBObject container=new BasicDBObject();
        child.addTo(container);
        and.add(container);
      }
      obj.put("String_Node_Str",and);
    }
 else {
      for (      final Criteria child : children) {
        child.addTo(obj);
      }
    }
  }
 else   if (joinMethod == CriteriaJoin.OR) {
    final BasicDBList or=new BasicDBList();
    for (    final Criteria child : children) {
      final BasicDBObject container=new BasicDBObject();
      child.addTo(container);
      or.add(container);
    }
    obj.put("String_Node_Str",or);
  }
}

Fixed version (ground truth):
public void addTo(final DBObject obj){
  if (joinMethod == CriteriaJoin.AND) {
    Map<String,Integer> fields=new HashMap<String,Integer>();
    for (    final Criteria child : children) {
      String field=child.getFieldName();
      if (null != field) {
        if (fields.containsKey(field))         fields.put(field,fields.get(field) + 1);
 else         fields.put(field,1);
      }
    }
    List<Criteria> ands=new ArrayList<Criteria>();
    for (    Criteria child : this.children) {
      String field=child.getFieldName();
      if (null != field || fields.get(field) <= 1) {
        child.addTo(obj);
      }
 else {
        ands.add(child);
      }
    }
    if (ands.size() > 0) {
      final BasicDBList and=new BasicDBList();
      for (      final Criteria child : ands) {
        final BasicDBObject container=new BasicDBObject();
        child.addTo(container);
        and.add(container);
      }
      obj.put("String_Node_Str",and);
    }
  }
 else   if (joinMethod == CriteriaJoin.OR) {
    final BasicDBList or=new BasicDBList();
    for (    final Criteria child : children) {
      final BasicDBObject container=new BasicDBObject();
      child.addTo(container);
      or.add(container);
    }
    obj.put("String_Node_Str",or);
  }
}