nus-yam/ex-repair huggingface dataset:
Program: 104723
Project: 104723
Buggy source:
public String getCollectionName(Object object){
  MappedClass mc=getMappedClass(object);
  return mc.getCollectionName();
}

Fixed version (ground truth):
public String getCollectionName(Object object){
  if (object == null)   throw new IllegalArgumentException();
  MappedClass mc=getMappedClass(object);
  return mc.getCollectionName();
}
Program: 104724
Project: 104724
Buggy source:
/** 
 * Add MappedClass to internal cache, possibly validating first. 
 */
private MappedClass addMappedClass(MappedClass mc,boolean validate){
  if (validate)   mc.validate();
  Converters c=(Converters)mc.getAnnotation(Converters.class);
  if (c != null)   for (  Class<? extends TypeConverter> clazz : c.value())   if (!converters.isRegistered(clazz))   converters.addConverter(clazz);
  mappedClasses.put(mc.getClazz().getName(),mc);
  Set<MappedClass> mcs=mappedClassesByCollection.get(mc.getCollectionName());
  if (mcs == null)   mcs=new HashSet();
  mcs.add(mc);
  return mc;
}

Fixed version (ground truth):
/** 
 * Add MappedClass to internal cache, possibly validating first. 
 */
private MappedClass addMappedClass(MappedClass mc,boolean validate){
  if (validate)   mc.validate();
  Converters c=(Converters)mc.getAnnotation(Converters.class);
  if (c != null)   for (  Class<? extends TypeConverter> clazz : c.value())   if (!converters.isRegistered(clazz))   converters.addConverter(clazz);
  mappedClasses.put(mc.getClazz().getName(),mc);
  Set<MappedClass> mcs=mappedClassesByCollection.get(mc.getCollectionName());
  if (mcs == null) {
    mcs=new HashSet();
    mappedClassesByCollection.put(mc.getCollectionName(),mcs);
  }
  mcs.add(mc);
  return mc;
}
Program: 104726
Project: 104726
Buggy source:
@Override public Object decode(Class targetClass,Object val,MappedField optionalExtraInfo) throws MappingException {
  if (val == null)   return null;
  if (val instanceof Double)   return (Double)val;
  if (val instanceof Number)   return ((Number)val).doubleValue();
  String sVal=val.toString();
  return Double.parseDouble(sVal);
}

Fixed version (ground truth):
@Override public Object decode(Class targetClass,Object val,MappedField optionalExtraInfo) throws MappingException {
  if (val == null)   return null;
  if (val instanceof Double)   return (Double)val;
  if (val instanceof Number)   return ((Number)val).doubleValue();
  if (val instanceof ArrayList)   return ReflectionUtils.convertToArray(double.class,(ArrayList)val);
  String sVal=val.toString();
  return Double.parseDouble(sVal);
}
Program: 104727
Project: 104727
Buggy source:
private Class discoverType(){
  Class type=field.getType();
  Type gType=field.getGenericType();
  TypeVariable<GenericDeclaration> tv=null;
  ParameterizedType pt=null;
  if (gType instanceof TypeVariable)   tv=(TypeVariable<GenericDeclaration>)gType;
 else   if (gType instanceof ParameterizedType)   pt=(ParameterizedType)gType;
  if (tv != null) {
    type=ReflectionUtils.getTypeArgument(persistedClass,tv);
  }
 else   if (pt != null) {
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + pt);
  }
  if (Object.class.equals(realType) && (tv != null || pt != null))   if (log.isWarningEnabled())   log.warning("String_Node_Str" + field.getName() + "String_Node_Str"+ field.getDeclaringClass());
  if (type == null)   throw new MappingException("String_Node_Str" + this.field);
  return type;
}

Fixed version (ground truth):
private Class discoverType(){
  Class type=field.getType();
  Type gType=field.getGenericType();
  TypeVariable<GenericDeclaration> tv=null;
  ParameterizedType pt=null;
  if (gType instanceof TypeVariable)   tv=(TypeVariable<GenericDeclaration>)gType;
 else   if (gType instanceof ParameterizedType)   pt=(ParameterizedType)gType;
  if (tv != null) {
    Class typeArgument=ReflectionUtils.getTypeArgument(persistedClass,tv);
    if (typeArgument != null)     type=typeArgument;
  }
 else   if (pt != null) {
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + pt);
  }
  if (Object.class.equals(realType) && (tv != null || pt != null))   if (log.isWarningEnabled())   log.warning("String_Node_Str" + field.getName() + "String_Node_Str"+ field.getDeclaringClass());
  if (type == null)   throw new MappingException("String_Node_Str" + this.field);
  return type;
}
Program: 104728
Project: 104728
Buggy source:
@SuppressWarnings("String_Node_Str") public void addTo(DBObject obj){
  if (FilterOperator.EQUAL.equals(this.operator)) {
    obj.put(this.field,this.value);
  }
 else {
    Object inner=obj.get(this.field);
    if (!(inner instanceof Map)) {
      inner=new HashMap<String,Object>();
      obj.put(this.field,inner);
    }
    ((Map<String,Object>)inner).put(this.operator.val(),this.value);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void addTo(DBObject obj){
  if (FilterOperator.EQUAL.equals(operator)) {
    obj.put(this.field,value);
  }
 else {
    Object inner=obj.get(field);
    if (!(inner instanceof Map)) {
      inner=new HashMap<String,Object>();
      obj.put(field,inner);
    }
    Object val=not ? new BasicDBObject("String_Node_Str",value) : value;
    ((Map<String,Object>)inner).put(operator.val(),val);
  }
}
Program: 104729
Project: 104729
Buggy source:
@SuppressWarnings("String_Node_Str") protected FieldCriteria(QueryImpl<?> query,String field,FilterOperator op,Object value,boolean validateNames,boolean validateTypes){
  StringBuffer sb=new StringBuffer(field);
  MappedField mf=Mapper.validate(query.getEntityClass(),query.getDatastore().getMapper(),sb,op,value,validateNames,validateTypes);
  field=sb.toString();
  Mapper mapr=query.getDatastore().getMapper();
  MappedClass mc=null;
  try {
    if (value != null && !ReflectionUtils.isPropertyType(value.getClass()) && !ReflectionUtils.implementsInterface(value.getClass(),Iterable.class))     if (mf != null && !mf.isTypeMongoCompatible())     mc=mapr.getMappedClass((mf.isSingleValue()) ? mf.getType() : mf.getSubClass());
 else     mc=mapr.getMappedClass(value);
  }
 catch (  Exception e) {
    log.debug("String_Node_Str",e);
  }
  Object mappedValue=mapr.toMongoObject(mf,mc,value);
  Class<?> type=(mappedValue == null) ? null : mappedValue.getClass();
  if (type != null && (op == FilterOperator.IN || op == FilterOperator.NOT_IN) && !type.isArray() && !Iterable.class.isAssignableFrom(type)) {
    mappedValue=Collections.singletonList(mappedValue);
  }
  if (op == FilterOperator.ELEMENT_MATCH && mappedValue instanceof DBObject)   ((DBObject)mappedValue).removeField(Mapper.ID_KEY);
  this.field=field;
  this.operator=op;
  this.value=mappedValue;
}

Fixed version (ground truth):
protected FieldCriteria(QueryImpl<?> query,String field,FilterOperator op,Object value,boolean validateNames,boolean validateTypes,boolean not){
  StringBuffer sb=new StringBuffer(field);
  MappedField mf=Mapper.validate(query.getEntityClass(),query.getDatastore().getMapper(),sb,op,value,validateNames,validateTypes);
  field=sb.toString();
  Mapper mapr=query.getDatastore().getMapper();
  MappedClass mc=null;
  try {
    if (value != null && !ReflectionUtils.isPropertyType(value.getClass()) && !ReflectionUtils.implementsInterface(value.getClass(),Iterable.class))     if (mf != null && !mf.isTypeMongoCompatible())     mc=mapr.getMappedClass((mf.isSingleValue()) ? mf.getType() : mf.getSubClass());
 else     mc=mapr.getMappedClass(value);
  }
 catch (  Exception e) {
    log.debug("String_Node_Str",e);
  }
  Object mappedValue=mapr.toMongoObject(mf,mc,value);
  Class<?> type=(mappedValue == null) ? null : mappedValue.getClass();
  if (type != null && (op == FilterOperator.IN || op == FilterOperator.NOT_IN) && !type.isArray() && !Iterable.class.isAssignableFrom(type)) {
    mappedValue=Collections.singletonList(mappedValue);
  }
  if (op == FilterOperator.ELEMENT_MATCH && mappedValue instanceof DBObject)   ((DBObject)mappedValue).removeField(Mapper.ID_KEY);
  this.field=field;
  this.operator=op;
  if (not)   this.value=new BasicDBObject("String_Node_Str",mappedValue);
 else   this.value=mappedValue;
  this.not=not;
}
Program: 104730
Project: 104730
Buggy source:
/** 
 * Add a criteria 
 */
private T addCrit(FilterOperator op,Object val){
  target.add(new FieldCriteria(query,field,op,val,validateName,query.isValidatingTypes()));
  return target;
}

Fixed version (ground truth):
/** 
 * Add a criteria 
 */
private T addCrit(FilterOperator op,Object val){
  target.add(new FieldCriteria(query,field,op,val,validateName,query.isValidatingTypes(),not));
  return target;
}
Program: 104731
Project: 104731
Buggy source:
private T addGeoCrit(FilterOperator op,Object val,Map<String,Object> opts){
  target.add(new GeoFieldCriteria(query,field,op,val,validateName,false,opts));
  return target;
}

Fixed version (ground truth):
private T addGeoCrit(FilterOperator op,Object val,Map<String,Object> opts){
  if (not)   throw new QueryException("String_Node_Str");
  target.add(new GeoFieldCriteria(query,field,op,val,validateName,false,opts));
  return target;
}
Program: 104732
Project: 104732
Buggy source:
public FieldEndImpl(QueryImpl<?> query,String field,T target,boolean validateName){
  this.query=query;
  this.field=field;
  this.target=target;
  this.validateName=validateName;
}

Fixed version (ground truth):
public FieldEndImpl(QueryImpl<?> query,String field,T target,boolean validateName){
  this(query,field,target,validateName,false);
}
Program: 104733
Project: 104733
Buggy source:
public DBObject getFieldsObject(){
  if (fields == null || fields.length == 0)   return null;
  Map<String,Boolean> fieldsFilter=new HashMap<String,Boolean>();
  for (  String field : this.fields)   fieldsFilter.put(field,(includeFields));
  return new BasicDBObject(fieldsFilter);
}

Fixed version (ground truth):
public DBObject getFieldsObject(){
  if (fields == null || fields.length == 0)   return null;
  Map<String,Boolean> fieldsFilter=new HashMap<String,Boolean>();
  for (  String field : this.fields) {
    StringBuffer sb=new StringBuffer(field);
    Mapper.validate(clazz,ds.getMapper(),sb,FilterOperator.EQUAL,null,validateName,false);
    field=sb.toString();
    fieldsFilter.put(field,(includeFields));
  }
  return new BasicDBObject(fieldsFilter);
}
Program: 104734
Project: 104734
Buggy source:
<T>void delete(String kind,T id);

Fixed version (ground truth):
<T>WriteResult delete(String kind,T id);
Program: 104735
Project: 104735
Buggy source:
/** 
 * Deletes the given entity (by @Id), with the WriteConcern 
 */
<T>void delete(T entity,WriteConcern wc);

Fixed version (ground truth):
/** 
 * Deletes the given entity (by @Id), with the WriteConcern 
 */
<T>WriteResult delete(T entity,WriteConcern wc);
Program: 104736
Project: 104736
Buggy source:
public <T>void delete(Query<T> query,WriteConcern wc){
  QueryImpl<T> q=(QueryImpl<T>)query;
  DBCollection dbColl=q.getCollection();
  if (dbColl == null)   dbColl=getCollection(q.getEntityClass());
  WriteResult wr;
  if (q.getSortObject() != null || q.getOffset() != 0 || q.getLimit() > 0)   throw new QueryException("String_Node_Str");
  if (q.getQueryObject() != null)   if (wc == null)   wr=dbColl.remove(q.getQueryObject());
 else   wr=dbColl.remove(q.getQueryObject(),wc);
 else   if (wc == null)   wr=dbColl.remove(new BasicDBObject());
 else   wr=dbColl.remove(new BasicDBObject(),wc);
  throwOnError(wc,wr);
}

Fixed version (ground truth):
public <T>WriteResult delete(Query<T> query,WriteConcern wc){
  QueryImpl<T> q=(QueryImpl<T>)query;
  DBCollection dbColl=q.getCollection();
  if (dbColl == null)   dbColl=getCollection(q.getEntityClass());
  WriteResult wr;
  if (q.getSortObject() != null || q.getOffset() != 0 || q.getLimit() > 0)   throw new QueryException("String_Node_Str");
  if (q.getQueryObject() != null)   if (wc == null)   wr=dbColl.remove(q.getQueryObject());
 else   wr=dbColl.remove(q.getQueryObject(),wc);
 else   if (wc == null)   wr=dbColl.remove(new BasicDBObject());
 else   wr=dbColl.remove(new BasicDBObject(),wc);
  throwOnError(wc,wr);
  return wr;
}
Program: 104737
Project: 104737
Buggy source:
public void delete(T entity,WriteConcern wc){
  ds.delete(entity,wc);
}

Fixed version (ground truth):
public WriteResult delete(T entity,WriteConcern wc){
  return ds.delete(entity,wc);
}
Program: 104738
Project: 104738
Buggy source:
public void deleteByQuery(Query q){
  ds.delete(q);
}

Fixed version (ground truth):
public WriteResult deleteByQuery(Query q){
  return ds.delete(q);
}
Program: 104739
Project: 104739
Buggy source:
public void deleteById(K id){
  ds.delete(entityClazz,id);
}

Fixed version (ground truth):
public WriteResult deleteById(K id){
  return ds.delete(entityClazz,id);
}
Program: 104740
Project: 104740
Buggy source:
/** 
 * Deletes the entity 
 */
public void delete(T entity,WriteConcern wc);

Fixed version (ground truth):
/** 
 * Deletes the entity 
 * @return 
 */
public WriteResult delete(T entity,WriteConcern wc);
Program: 104741
Project: 104741
Buggy source:
/** 
 * Saves the entities given the query
 */
public void deleteByQuery(Query<T> q);

Fixed version (ground truth):
/** 
 * Saves the entities given the query
 */
public WriteResult deleteByQuery(Query<T> q);
Program: 104742
Project: 104742
Buggy source:
/** 
 * Delete the entity by id value 
 */
public void deleteById(K id);

Fixed version (ground truth):
/** 
 * Delete the entity by id value 
 */
public WriteResult deleteById(K id);
Program: 104743
Project: 104743
Buggy source:
@Test public void testGet() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  Rectangle rectLoaded=ads.get(ns,Rectangle.class,rect.getId());
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
}

Fixed version (ground truth):
@Test public void testGet() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  db.getCollection(ns).remove(new BasicDBObject());
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  Rectangle rectLoaded=ads.get(ns,Rectangle.class,rect.getId());
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
}
Program: 104744
Project: 104744
Buggy source:
@Test public void testSaveAndDelete() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  ads.delete(ns,1);
  assertEquals(1,ads.getCount(ns));
  ads.delete(ns,"String_Node_Str");
  assertEquals(0,ads.getCount(ns));
}

Fixed version (ground truth):
@Test public void testSaveAndDelete() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  db.getCollection(ns).remove(new BasicDBObject());
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  ads.delete(ns,1);
  assertEquals(1,ads.getCount(ns));
  ads.delete(ns,"String_Node_Str");
  assertEquals(0,ads.getCount(ns));
}
Program: 104745
Project: 104745
Buggy source:
@Test public void testFind() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  Rectangle rectLoaded=ads.find(ns,Rectangle.class).get();
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
  rect=new Rectangle(2,1);
  rect.setId("String_Node_Str");
  ads.save(rect);
  assertEquals(1,ads.getCount(rect));
  rect.setId("String_Node_Str");
  ads.save(rect);
  assertEquals(2,ads.getCount(rect));
  rect=new Rectangle(4,3);
  rect.setId("String_Node_Str");
  ads.save(ns,rect);
  assertEquals(2,ads.getCount(ns));
  List<Rectangle> rects=ads.find(ns,Rectangle.class).asList();
  rectLoaded=rects.get(1);
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
  rectLoaded=ads.find(ns,Rectangle.class,"String_Node_Str","String_Node_Str",1,1).get();
}

Fixed version (ground truth):
@Test public void testFind() throws Exception {
  String ns="String_Node_Str";
  Rectangle rect=new Rectangle(10,10);
  rect.setId("String_Node_Str");
  db.getCollection(ns).remove(new BasicDBObject());
  ads.save(ns,rect);
  assertEquals(1,ads.getCount(ns));
  Rectangle rectLoaded=ads.find(ns,Rectangle.class).get();
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
  rect=new Rectangle(2,1);
  rect.setId("String_Node_Str");
  ads.save(rect);
  assertEquals(1,ads.getCount(rect));
  rect.setId("String_Node_Str");
  ads.save(rect);
  assertEquals(2,ads.getCount(rect));
  rect=new Rectangle(4,3);
  rect.setId("String_Node_Str");
  ads.save(ns,rect);
  assertEquals(2,ads.getCount(ns));
  List<Rectangle> rects=ads.find(ns,Rectangle.class).asList();
  rectLoaded=rects.get(1);
  assertEquals(rect.getId(),rectLoaded.getId());
  assertEquals(rect.getArea(),rectLoaded.getArea(),0);
  rectLoaded=ads.find(ns,Rectangle.class,"String_Node_Str","String_Node_Str",1,1).get();
}
Program: 104746
Project: 104746
Buggy source:
private <T>void postSaveOperations(Object entity,DBObject dbObj,Map<Object,DBObject> involvedObjects){
  MappedClass mc=mapr.getMappedClass(entity);
  mapr.updateKeyInfo(entity,dbObj,createCache());
  firePostPersistForChildren(involvedObjects);
  mc.callLifecycleMethods(PostPersist.class,entity,dbObj,mapr);
}

Fixed version (ground truth):
private <T>void postSaveOperations(Object entity,DBObject dbObj,Map<Object,DBObject> involvedObjects){
  mapr.updateKeyInfo(entity,dbObj,createCache());
  for (  Map.Entry<Object,DBObject> e : involvedObjects.entrySet()) {
    Object ent=e.getKey();
    DBObject dbO=e.getValue();
    MappedClass mc=mapr.getMappedClass(entity);
    mc.callLifecycleMethods(PostPersist.class,ent,dbO,mapr);
  }
}
Program: 104747
Project: 104747
Buggy source:
@PreLoad void PreLoad(){
  preLoad=true;
}

Fixed version (ground truth):
@PreLoad void PreLoad(){
  if (preLoad == true)   throw new RuntimeException("String_Node_Str");
  preLoad=true;
}
Program: 104748
Project: 104748
Buggy source:
@PreLoad void PostLoadWithParam(DBObject dbObj){
  postLoadWithParam=true;
}

Fixed version (ground truth):
@PreLoad void PostLoadWithParam(DBObject dbObj){
  if (postLoadWithParam == true)   throw new RuntimeException("String_Node_Str");
  postLoadWithParam=true;
}
Program: 104749
Project: 104749
Buggy source:
@PrePersist protected void PrePersistWithParam(DBObject dbObj){
  prePersistWithParam=true;
}

Fixed version (ground truth):
@PrePersist protected void PrePersistWithParam(DBObject dbObj){
  if (prePersistWithParam == true)   throw new RuntimeException("String_Node_Str");
  prePersistWithParam=true;
}
Program: 104750
Project: 104750
Buggy source:
@PostLoad void PostLoad(){
  postLoad=true;
}

Fixed version (ground truth):
@PostLoad void PostLoad(){
  if (postLoad == true)   throw new RuntimeException("String_Node_Str");
  postLoad=true;
}
Program: 104751
Project: 104751
Buggy source:
@SuppressWarnings("String_Node_Str") @PostPersist private void PostPersistPersist(){
  postPersist=true;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @PostPersist private void PostPersistPersist(){
  if (postPersist == true)   throw new RuntimeException("String_Node_Str");
  postPersist=true;
}
Program: 104752
Project: 104752
Buggy source:
@PrePersist public DBObject PrePersistWithParamAndReturn(DBObject dbObj){
  prePersistWithParamAndReturn=true;
  return null;
}

Fixed version (ground truth):
@PrePersist public DBObject PrePersistWithParamAndReturn(DBObject dbObj){
  if (prePersistWithParamAndReturn == true)   throw new RuntimeException("String_Node_Str");
  prePersistWithParamAndReturn=true;
  return null;
}
Program: 104753
Project: 104753
Buggy source:
@PrePersist void PrePersist(){
  prePersist=true;
}

Fixed version (ground truth):
@PrePersist void PrePersist(){
  if (prePersist == true)   throw new RuntimeException("String_Node_Str");
  prePersist=true;
}
Program: 104754
Project: 104754
Buggy source:
@Override protected void check(MappedClass mc,MappedField mf,Set<ConstraintViolation> ve){
  if (mf.isMap() && (!mf.hasAnnotation(Serialized.class))) {
    Class<?> parameterizedClass=ReflectionUtils.getParameterizedClass(mf.getField(),0);
    if (parameterizedClass == null) {
      ve.add(new ConstraintViolation(Level.WARNING,mc,mf,this.getClass(),"String_Node_Str" + supportedExample));
    }
 else     if (!parameterizedClass.equals(String.class) && !ReflectionUtils.isPrimitiveLike(parameterizedClass))     ve.add(new ConstraintViolation(Level.FATAL,mc,mf,this.getClass(),"String_Node_Str" + supportedExample + "String_Node_Str"+ parameterizedClass+ "String_Node_Str"));
  }
}

Fixed version (ground truth):
@Override protected void check(MappedClass mc,MappedField mf,Set<ConstraintViolation> ve){
  if (mf.isMap() && (!mf.hasAnnotation(Serialized.class))) {
    Class<?> parameterizedClass=ReflectionUtils.getParameterizedClass(mf.getField(),0);
    if (parameterizedClass == null) {
      ve.add(new ConstraintViolation(Level.WARNING,mc,mf,this.getClass(),"String_Node_Str" + supportedExample));
    }
 else     if (!parameterizedClass.equals(String.class) && !parameterizedClass.equals(ObjectId.class) && !ReflectionUtils.isPrimitiveLike(parameterizedClass))     ve.add(new ConstraintViolation(Level.FATAL,mc,mf,this.getClass(),"String_Node_Str" + supportedExample + "String_Node_Str"+ parameterizedClass+ "String_Node_Str"));
  }
}
Program: 104755
Project: 104755
Buggy source:
@Test public void testObjectIdKeyedMap() throws Exception {
  ContainsObjectIdKeyMap map=new ContainsObjectIdKeyMap();
  ObjectId o1=new ObjectId("String_Node_Str");
  ObjectId o2=new ObjectId("String_Node_Str");
  map.values.put(o1,"String_Node_Str");
  map.values.put(o2,"String_Node_Str");
  Key<?> mapKey=ds.save(map);
  ContainsObjectIdKeyMap mapLoaded=ds.get(ContainsObjectIdKeyMap.class,mapKey.getId());
  assertNotNull(mapLoaded);
  assertEquals(2,mapLoaded.values.size());
  assertNotNull(mapLoaded.values.get(o1));
  assertNotNull(mapLoaded.values.get(o2));
  assertNotNull(ds.find(ContainsIntKeyMap.class).field("String_Node_Str").exists());
  assertEquals(0,ds.find(ContainsIntKeyMap.class).field("String_Node_Str").doesNotExist().countAll());
  assertNotNull(ds.find(ContainsIntKeyMap.class).field("String_Node_Str").doesNotExist());
  assertEquals(0,ds.find(ContainsIntKeyMap.class).field("String_Node_Str").exists().countAll());
}

Fixed version (ground truth):
@Test public void testObjectIdKeyedMap() throws Exception {
  morphia.map(ContainsObjectIdKeyMap.class);
  ContainsObjectIdKeyMap map=new ContainsObjectIdKeyMap();
  ObjectId o1=new ObjectId("String_Node_Str");
  ObjectId o2=new ObjectId("String_Node_Str");
  map.values.put(o1,"String_Node_Str");
  map.values.put(o2,"String_Node_Str");
  Key<?> mapKey=ds.save(map);
  ContainsObjectIdKeyMap mapLoaded=ds.get(ContainsObjectIdKeyMap.class,mapKey.getId());
  assertNotNull(mapLoaded);
  assertEquals(2,mapLoaded.values.size());
  assertNotNull(mapLoaded.values.get(o1));
  assertNotNull(mapLoaded.values.get(o2));
  assertNotNull(ds.find(ContainsIntKeyMap.class).field("String_Node_Str").exists());
  assertEquals(0,ds.find(ContainsIntKeyMap.class).field("String_Node_Str").doesNotExist().countAll());
  assertNotNull(ds.find(ContainsIntKeyMap.class).field("String_Node_Str").doesNotExist());
  assertEquals(0,ds.find(ContainsIntKeyMap.class).field("String_Node_Str").exists().countAll());
}
Program: 104756
Project: 104756
Buggy source:
<T>Query<T> createQuery(Class<T> kind,DBObject q);

Fixed version (ground truth):
<T>Query<T> createQuery(String kind,Class<T> clazz,DBObject q);
Program: 104757
Project: 104757
Buggy source:
private <T>UpdateResults<T> update(Query<T> query,DBObject u,boolean createIfMissing,boolean multi,WriteConcern wc){
  DBCollection dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qImpl=(QueryImpl<T>)query;
  if (qImpl.getSortObject() != null && qImpl.getSortObject().keySet() != null && !qImpl.getSortObject().keySet().isEmpty())   throw new QueryException("String_Node_Str");
  if (qImpl.getOffset() > 0)   throw new QueryException("String_Node_Str");
  if (qImpl.getLimit() > 0)   throw new QueryException("String_Node_Str");
  DBObject q=qImpl.getQueryObject();
  if (q == null)   q=new BasicDBObject();
  if (log.isTraceEnabled())   log.trace("String_Node_Str" + dbColl.getName() + "String_Node_Str"+ q+ "String_Node_Str"+ u+ "String_Node_Str"+ multi+ "String_Node_Str"+ createIfMissing);
  WriteResult wr;
  if (wc == null)   wr=dbColl.update(q,u,createIfMissing,multi);
 else   wr=dbColl.update(q,u,createIfMissing,multi,wc);
  throwOnError(wc,wr);
  return new UpdateResults<T>(wr);
}

Fixed version (ground truth):
private <T>UpdateResults<T> update(Query<T> query,DBObject u,boolean createIfMissing,boolean multi,WriteConcern wc){
  QueryImpl<T> qi=(QueryImpl<T>)query;
  DBCollection dbColl=qi.getCollection();
  if (dbColl == null)   dbColl=getCollection(qi.getEntityClass());
  if (qi.getSortObject() != null && qi.getSortObject().keySet() != null && !qi.getSortObject().keySet().isEmpty())   throw new QueryException("String_Node_Str");
  if (qi.getOffset() > 0)   throw new QueryException("String_Node_Str");
  if (qi.getLimit() > 0)   throw new QueryException("String_Node_Str");
  DBObject q=qi.getQueryObject();
  if (q == null)   q=new BasicDBObject();
  if (log.isTraceEnabled())   log.trace("String_Node_Str" + dbColl.getName() + "String_Node_Str"+ q+ "String_Node_Str"+ u+ "String_Node_Str"+ multi+ "String_Node_Str"+ createIfMissing);
  WriteResult wr;
  if (wc == null)   wr=dbColl.update(q,u,createIfMissing,multi);
 else   wr=dbColl.update(q,u,createIfMissing,multi,wc);
  throwOnError(wc,wr);
  return new UpdateResults<T>(wr);
}
Program: 104758
Project: 104758
Buggy source:
public <T>UpdateResults<T> updateFirst(Query<T> query,T entity,boolean createIfMissing){
  LinkedHashMap<Object,DBObject> involvedObjects=new LinkedHashMap<Object,DBObject>();
  DBObject dbObj=mapr.toDBObject(entity,involvedObjects);
  UpdateResults<T> res=update(query,dbObj,createIfMissing,false,getWriteConcern(entity));
  CommandResult gle=res.getWriteResult().getCachedLastError();
  if (gle != null && res.getInsertedCount() > 0)   dbObj.put(Mapper.ID_KEY,res.getNewId());
  postSaveOperations(entity,dbObj,getCollection(entity),involvedObjects);
  return res;
}

Fixed version (ground truth):
public <T>UpdateResults<T> updateFirst(Query<T> query,T entity,boolean createIfMissing){
  LinkedHashMap<Object,DBObject> involvedObjects=new LinkedHashMap<Object,DBObject>();
  DBObject dbObj=mapr.toDBObject(entity,involvedObjects);
  UpdateResults<T> res=update(query,dbObj,createIfMissing,false,getWriteConcern(entity));
  CommandResult gle=res.getWriteResult().getCachedLastError();
  if (gle != null && res.getInsertedCount() > 0)   dbObj.put(Mapper.ID_KEY,res.getNewId());
  postSaveOperations(entity,dbObj,involvedObjects);
  return res;
}
Program: 104759
Project: 104759
Buggy source:
public <T>T findAndDelete(Query<T> query){
  DBCollection dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qi=((QueryImpl<T>)query);
  EntityCache cache=createCache();
  if (log.isTraceEnabled())   log.trace("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject result=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),true,null,false,false);
  if (result != null) {
    T entity=(T)mapr.fromDBObject(qi.getEntityClass(),result,cache);
    return entity;
  }
  return null;
}

Fixed version (ground truth):
public <T>T findAndDelete(Query<T> query){
  DBCollection dbColl=((QueryImpl<T>)query).getCollection();
  if (dbColl == null)   dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qi=((QueryImpl<T>)query);
  EntityCache cache=createCache();
  if (log.isTraceEnabled())   log.trace("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject result=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),true,null,false,false);
  if (result != null) {
    T entity=(T)mapr.fromDBObject(qi.getEntityClass(),result,cache);
    return entity;
  }
  return null;
}
Program: 104760
Project: 104760
Buggy source:
public <T>void delete(Query<T> query,WriteConcern wc){
  QueryImpl<T> q=(QueryImpl<T>)query;
  DBCollection dbColl=getCollection(q.getEntityClass());
  WriteResult wr;
  if (q.getSortObject() != null || q.getOffset() != 0 || q.getLimit() > 0)   throw new QueryException("String_Node_Str");
  if (q.getQueryObject() != null)   if (wc == null)   wr=dbColl.remove(q.getQueryObject());
 else   wr=dbColl.remove(q.getQueryObject(),wc);
 else   if (wc == null)   wr=dbColl.remove(new BasicDBObject());
 else   wr=dbColl.remove(new BasicDBObject(),wc);
  throwOnError(wc,wr);
}

Fixed version (ground truth):
public <T>void delete(Query<T> query,WriteConcern wc){
  QueryImpl<T> q=(QueryImpl<T>)query;
  DBCollection dbColl=q.getCollection();
  if (dbColl == null)   dbColl=getCollection(q.getEntityClass());
  WriteResult wr;
  if (q.getSortObject() != null || q.getOffset() != 0 || q.getLimit() > 0)   throw new QueryException("String_Node_Str");
  if (q.getQueryObject() != null)   if (wc == null)   wr=dbColl.remove(q.getQueryObject());
 else   wr=dbColl.remove(q.getQueryObject(),wc);
 else   if (wc == null)   wr=dbColl.remove(new BasicDBObject());
 else   wr=dbColl.remove(new BasicDBObject(),wc);
  throwOnError(wc,wr);
}
Program: 104761
Project: 104761
Buggy source:
/** 
 * call postSaveOperations and returns Key for entity 
 */
protected <T>Key<T> postSaveGetKey(T entity,DBObject dbObj,DBCollection dbColl,Map<Object,DBObject> involvedObjects){
  if (dbObj.get(Mapper.ID_KEY) == null)   throw new MappingException("String_Node_Str");
  postSaveOperations(entity,dbObj,dbColl,involvedObjects);
  Key<T> key=new Key<T>(dbColl.getName(),getId(entity));
  key.setKindClass((Class<? extends T>)entity.getClass());
  return key;
}

Fixed version (ground truth):
/** 
 * call postSaveOperations and returns Key for entity 
 */
protected <T>Key<T> postSaveGetKey(T entity,DBObject dbObj,DBCollection dbColl,Map<Object,DBObject> involvedObjects){
  if (dbObj.get(Mapper.ID_KEY) == null)   throw new MappingException("String_Node_Str");
  postSaveOperations(entity,dbObj,involvedObjects);
  Key<T> key=new Key<T>(dbColl.getName(),getId(entity));
  key.setKindClass((Class<? extends T>)entity.getClass());
  return key;
}
Program: 104762
Project: 104762
Buggy source:
public <T>Key<T> merge(T entity,WriteConcern wc){
  LinkedHashMap<Object,DBObject> involvedObjects=new LinkedHashMap<Object,DBObject>();
  DBObject dbObj=mapr.toDBObject(entity,involvedObjects);
  Key<T> key=getKey(entity);
  entity=ProxyHelper.unwrap(entity);
  Object id=getId(entity);
  if (id == null)   throw new MappingException("String_Node_Str" + entity.getClass().getName());
  Query<T> query=(Query<T>)createQuery(entity.getClass()).filter(Mapper.ID_KEY,id);
  dbObj.removeField(Mapper.ID_KEY);
  UpdateResults<T> res=update(query,new BasicDBObject("String_Node_Str",dbObj),false,false,wc);
  CommandResult gle=res.getWriteResult().getCachedLastError();
  if (gle != null && res.getUpdatedCount() == 0)   throw new UpdateException("String_Node_Str" + gle);
  postSaveOperations(entity,dbObj,getCollection(entity),involvedObjects);
  return key;
}

Fixed version (ground truth):
public <T>Key<T> merge(T entity,WriteConcern wc){
  LinkedHashMap<Object,DBObject> involvedObjects=new LinkedHashMap<Object,DBObject>();
  DBObject dbObj=mapr.toDBObject(entity,involvedObjects);
  Key<T> key=getKey(entity);
  entity=ProxyHelper.unwrap(entity);
  Object id=getId(entity);
  if (id == null)   throw new MappingException("String_Node_Str" + entity.getClass().getName());
  Query<T> query=(Query<T>)createQuery(entity.getClass()).filter(Mapper.ID_KEY,id);
  dbObj.removeField(Mapper.ID_KEY);
  UpdateResults<T> res=update(query,new BasicDBObject("String_Node_Str",dbObj),false,false,wc);
  CommandResult gle=res.getWriteResult().getCachedLastError();
  if (gle != null && res.getUpdatedCount() == 0)   throw new UpdateException("String_Node_Str" + gle);
  postSaveOperations(entity,dbObj,involvedObjects);
  return key;
}
Program: 104763
Project: 104763
Buggy source:
private <T>void postSaveOperations(Object entity,DBObject dbObj,DBCollection dbColl,Map<Object,DBObject> involvedObjects){
  MappedClass mc=mapr.getMappedClass(entity);
  mapr.updateKeyInfo(entity,dbObj,createCache());
  firePostPersistForChildren(involvedObjects);
  mc.callLifecycleMethods(PostPersist.class,entity,dbObj,mapr);
}

Fixed version (ground truth):
private <T>void postSaveOperations(Object entity,DBObject dbObj,Map<Object,DBObject> involvedObjects){
  MappedClass mc=mapr.getMappedClass(entity);
  mapr.updateKeyInfo(entity,dbObj,createCache());
  firePostPersistForChildren(involvedObjects);
  mc.callLifecycleMethods(PostPersist.class,entity,dbObj,mapr);
}
Program: 104764
Project: 104764
Buggy source:
public <T>Query<T> createQuery(Class<T> kind,DBObject q){
  return new QueryImpl<T>(kind,getCollection(kind),this,q);
}

Fixed version (ground truth):
public <T>Query<T> createQuery(String kind,Class<T> clazz){
  return new QueryImpl<T>(clazz,db.getCollection(kind),this);
}
Program: 104766
Project: 104766
Buggy source:
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing){
  QueryImpl<T> qi=((QueryImpl<T>)query);
  DBCollection dbColl=getCollection((qi).getEntityClass());
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,createIfMissing);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}

Fixed version (ground truth):
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing){
  QueryImpl<T> qi=(QueryImpl<T>)query;
  DBCollection dbColl=qi.getCollection();
  if (dbColl == null)   dbColl=getCollection(qi.getEntityClass());
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,createIfMissing);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}
Program: 104767
Project: 104767
Buggy source:
/** 
 * Gets the write concern for entity or returns the default write concern for this datastore 
 */
public WriteConcern getWriteConcern(Object clazzOrEntity){
  if (clazzOrEntity != null) {
    Entity entityAnn=getMapper().getMappedClass(clazzOrEntity).getEntityAnnotation();
    if (entityAnn != null && entityAnn.concern() != null && entityAnn.concern() != "String_Node_Str")     return WriteConcern.valueOf(entityAnn.concern());
  }
  return defConcern;
}

Fixed version (ground truth):
/** 
 * Gets the write concern for entity or returns the default write concern for this datastore 
 */
public WriteConcern getWriteConcern(Object clazzOrEntity){
  WriteConcern wc=null;
  if (clazzOrEntity != null) {
    Entity entityAnn=getMapper().getMappedClass(clazzOrEntity).getEntityAnnotation();
    if (entityAnn != null && entityAnn.concern() != null && entityAnn.concern() != "String_Node_Str")     wc=WriteConcern.valueOf(entityAnn.concern());
  }
  if (wc == null)   wc=defConcern;
  return wc;
}
Program: 104768
Project: 104768
Buggy source:
public static Set<Class<?>> getClasses(final ClassLoader loader,final String packageName) throws IOException, ClassNotFoundException {
  Set<Class<?>> classes=new HashSet<Class<?>>();
  String path=packageName.replace('.','/');
  Enumeration<URL> resources=loader.getResources(path);
  if (resources != null) {
    while (resources.hasMoreElements()) {
      String filePath=resources.nextElement().getFile();
      if (filePath.indexOf("String_Node_Str") > 0) {
        filePath=filePath.replaceAll("String_Node_Str","String_Node_Str");
      }
      if (filePath != null) {
        if ((filePath.indexOf("String_Node_Str") > 0) & (filePath.indexOf("String_Node_Str") > 0)) {
          String jarPath=filePath.substring(0,filePath.indexOf("String_Node_Str")).substring(filePath.indexOf("String_Node_Str") + 1);
          if (jarPath.indexOf("String_Node_Str") >= 0) {
            jarPath=jarPath.substring(1);
          }
          classes.addAll(getFromJARFile(jarPath,path));
        }
 else {
          classes.addAll(getFromDirectory(new File(filePath),packageName));
        }
      }
    }
  }
  return classes;
}

Fixed version (ground truth):
public static Set<Class<?>> getClasses(final ClassLoader loader,final String packageName) throws IOException, ClassNotFoundException {
  Set<Class<?>> classes=new HashSet<Class<?>>();
  String path=packageName.replace('.','/');
  Enumeration<URL> resources=loader.getResources(path);
  if (resources != null) {
    while (resources.hasMoreElements()) {
      String filePath=resources.nextElement().getFile();
      if (filePath.indexOf("String_Node_Str") > 0)       filePath=filePath.replaceAll("String_Node_Str","String_Node_Str");
      if (filePath.indexOf("String_Node_Str") > 0)       filePath=filePath.replaceAll("String_Node_Str","String_Node_Str");
      if (filePath != null) {
        if ((filePath.indexOf("String_Node_Str") > 0) & (filePath.indexOf("String_Node_Str") > 0)) {
          String jarPath=filePath.substring(0,filePath.indexOf("String_Node_Str")).substring(filePath.indexOf("String_Node_Str") + 1);
          if (jarPath.indexOf("String_Node_Str") >= 0) {
            jarPath=jarPath.substring(1);
          }
          classes.addAll(getFromJARFile(jarPath,path));
        }
 else {
          classes.addAll(getFromDirectory(new File(filePath),packageName));
        }
      }
    }
  }
  return classes;
}
Program: 104769
Project: 104769
Buggy source:
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing){
  DBCollection dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qi=((QueryImpl<T>)query);
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,createIfMissing);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}

Fixed version (ground truth):
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing){
  QueryImpl<T> qi=((QueryImpl<T>)query);
  DBCollection dbColl=getCollection((qi).getEntityClass());
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,createIfMissing);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}
Program: 104770
Project: 104770
Buggy source:
@Override public Object decode(Class targetClass,Object val,MappedField optionalExtraInfo) throws MappingException {
  if (val == null)   return null;
  if (val instanceof Boolean)   return (Boolean)val;
  String sVal=val.toString();
  return Boolean.parseBoolean(sVal);
}

Fixed version (ground truth):
@Override public Object decode(Class targetClass,Object val,MappedField optionalExtraInfo) throws MappingException {
  if (val == null)   return null;
  if (val instanceof Boolean)   return (Boolean)val;
  if (val instanceof Number)   return ((Number)val).doubleValue() == 1D;
  String sVal=val.toString();
  return Boolean.parseBoolean(sVal);
}
Program: 104771
Project: 104771
Buggy source:
Object fromDb(DBObject dbObject,final Object entity,EntityCache cache){
  if (entity instanceof MappedField) {
    readMappedField(dbObject,(MappedField)entity,entity,cache);
    return entity;
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null && getMappedClass(entity).getEntityAnnotation() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    Object cachedInstance=cache.getEntity(key);
    if (cachedInstance != null)     return cachedInstance;
 else     cache.putEntity(key,entity);
  }
  MappedClass mc=getMappedClass(entity);
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PreLoad.class,entity,dbObject,this);
  try {
    for (    MappedField mf : mc.getPersistenceFields()) {
      readMappedField(dbObject,mf,entity,cache);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    cache.putEntity(key,entity);
  }
  mc.callLifecycleMethods(PostLoad.class,entity,dbObject,this);
  return entity;
}

Fixed version (ground truth):
Object fromDb(DBObject dbObject,Object entity,EntityCache cache){
  if (entity instanceof MappedField) {
    readMappedField(dbObject,(MappedField)entity,entity,cache);
    return entity;
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null && getMappedClass(entity).getEntityAnnotation() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    Object cachedInstance=cache.getEntity(key);
    if (cachedInstance != null)     return cachedInstance;
 else     cache.putEntity(key,entity);
  }
  MappedClass mc=getMappedClass(entity);
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PreLoad.class,entity,dbObject,this);
  try {
    for (    MappedField mf : mc.getPersistenceFields()) {
      readMappedField(dbObject,mf,entity,cache);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    cache.putEntity(key,entity);
  }
  mc.callLifecycleMethods(PostLoad.class,entity,dbObject,this);
  return entity;
}
Program: 104772
Project: 104772
Buggy source:
@Before public void setUp(){
  this.db=this.mongo.getDB("String_Node_Str");
  this.ds=this.morphia.createDatastore(this.mongo,this.db.getName());
}

Fixed version (ground truth):
@Before public void setUp(){
  this.db=this.mongo.getDB("String_Node_Str");
  this.ds=this.morphia.createDatastore(this.mongo,this.db.getName());
  this.ads=(AdvancedDatastore)ds;
}
Program: 104773
Project: 104773
Buggy source:
public static <T>Class<?> getTypeArgument(Class<? extends T> clazz,TypeVariable<? extends GenericDeclaration> tv){
  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 {
      ParameterizedType parameterizedType=(ParameterizedType)type;
      Class<?> rawType=(Class)parameterizedType.getRawType();
      Type[] actualTypeArguments=parameterizedType.getActualTypeArguments();
      TypeVariable<?>[] typeParameters=rawType.getTypeParameters();
      for (int i=0; i < actualTypeArguments.length; i++) {
        if (typeParameters[i].equals(tv))         return getClass(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(Class<? extends T> clazz,TypeVariable<? extends GenericDeclaration> tv){
  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 {
      ParameterizedType parameterizedType=(ParameterizedType)type;
      Class<?> rawType=(Class)parameterizedType.getRawType();
      Type[] actualTypeArguments=parameterizedType.getActualTypeArguments();
      TypeVariable<?>[] typeParameters=rawType.getTypeParameters();
      for (int i=0; i < actualTypeArguments.length; i++) {
        if (typeParameters[i].equals(tv)) {
          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;
}
Program: 104774
Project: 104774
Buggy source:
/** 
 * Gets the write concern for entity or returns the default write concern for this datastore 
 */
public WriteConcern getWriteConcern(Object clazzOrEntity){
  WriteConcern wc=null;
  if (clazzOrEntity != null) {
    Entity entityAnn=getMapper().getMappedClass(clazzOrEntity).getEntityAnnotation();
    if (entityAnn != null && entityAnn.concern() != null && entityAnn.concern() != "String_Node_Str")     wc=WriteConcern.valueOf(entityAnn.concern());
  }
  if (wc == null)   wc=defConcern;
  return wc;
}

Fixed version (ground truth):
/** 
 * Gets the write concern for entity or returns the default write concern for this datastore 
 */
public WriteConcern getWriteConcern(Object clazzOrEntity){
  WriteConcern wc=null;
  if (clazzOrEntity != null) {
    Entity entityAnn=getMapper().getMappedClass(clazzOrEntity).getEntityAnnotation();
    if (entityAnn != null && entityAnn.concern() != null && !"String_Node_Str".equals(entityAnn.concern()))     wc=WriteConcern.valueOf(entityAnn.concern());
  }
  if (wc == null)   wc=defConcern;
  return wc;
}
Program: 104775
Project: 104775
Buggy source:
/** 
 * Find the first Entity from the Query, and modify it.
 * @param q the query to find the Entity with; You are not allowed to offset/skip in the query.
 * @param oldVersion indicated the old version of the Entity should be returned
 * @return The Entity (the result of the update if oldVersion is false)
 */
<T>T findAndModify(Query<T> q,UpdateOperations<T> ops,boolean oldVersion);

Fixed version (ground truth):
/** 
 * Find the first Entity from the Query, and modify it.
 * @param q the query to find the Entity with; You are not allowed to offset/skip in the query.
 * @param oldVersion indicated the old version of the Entity should be returned
 * @param createIfMissing if the query returns no results, then a new object will be created (sets upsert=true)
 * @return The Entity (the result of the update if oldVersion is false)
 */
<T>T findAndModify(Query<T> q,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing);
Program: 104776
Project: 104776
Buggy source:
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion){
  DBCollection dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qi=((QueryImpl<T>)query);
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,false);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}

Fixed version (ground truth):
public <T>T findAndModify(Query<T> query,UpdateOperations<T> ops,boolean oldVersion,boolean createIfMissing){
  DBCollection dbColl=getCollection(((QueryImpl<T>)query).getEntityClass());
  QueryImpl<T> qi=((QueryImpl<T>)query);
  if (log.isTraceEnabled())   log.info("String_Node_Str" + dbColl.getName() + "String_Node_Str");
  DBObject res=dbColl.findAndModify(qi.getQueryObject(),qi.getFieldsObject(),qi.getSortObject(),false,((UpdateOpsImpl<T>)ops).getOps(),!oldVersion,createIfMissing);
  if (res == null)   return null;
 else   return (T)mapr.fromDBObject(qi.getEntityClass(),res,createCache());
}
Program: 104777
Project: 104777
Buggy source:
public DatastoreImpl(Morphia morphia,Mongo mongo,String dbName){
  this(morphia,mongo,dbName,null,null);
}

Fixed version (ground truth):
public DatastoreImpl(Morphia morphia,Mongo mongo,String dbName){
  this(morphia.getMapper(),mongo,dbName);
}