Program: 86777
Project: 86777
Buggy source:
/** 
 * @see DataSetQueryDAO#getPropertyValues(Class,String,EvaluationContext)
 */
public Map<Integer,Object> getPropertyValues(Class<? extends OpenmrsObject> type,String property,EvaluationContext context){
  Map<Integer,Object> ret=new HashMap<Integer,Object>();
  Cohort baseCohort=context.getBaseCohort();
  if (baseCohort != null && baseCohort.isEmpty()) {
    return ret;
  }
  ClassMetadata metadata=sessionFactory.getClassMetadata(type);
  String idPropertyName=metadata.getIdentifierPropertyName();
  String entityName=type.getSimpleName();
  String alias=entityName.toLowerCase();
  Map<Class<? extends OpenmrsData>,String> patientJoinProperties=new HashMap<Class<? extends OpenmrsData>,String>();
  patientJoinProperties.put(Person.class,"String_Node_Str");
  patientJoinProperties.put(Patient.class,"String_Node_Str");
  patientJoinProperties.put(Encounter.class,"String_Node_Str");
  patientJoinProperties.put(Obs.class,"String_Node_Str");
  patientJoinProperties.put(Order.class,"String_Node_Str");
  patientJoinProperties.put(PatientProgram.class,"String_Node_Str");
  patientJoinProperties.put(PatientState.class,"String_Node_Str");
  patientJoinProperties.put(PersonName.class,"String_Node_Str");
  patientJoinProperties.put(PatientIdentifier.class,"String_Node_Str");
  patientJoinProperties.put(Relationship.class,"String_Node_Str");
  String voidedProperty=(type == Person.class ? "String_Node_Str" : "String_Node_Str");
  boolean filterInQuery=baseCohort != null && baseCohort.size() < 2000;
  boolean doNotFilterInJava=baseCohort == null || filterInQuery;
  StringBuilder hql=new StringBuilder();
  hql.append("String_Node_Str" + idPropertyName + "String_Node_Str"+ property+ "String_Node_Str");
  hql.append("String_Node_Str" + entityName + "String_Node_Str"+ alias+ "String_Node_Str");
  hql.append("String_Node_Str" + alias + "String_Node_Str"+ voidedProperty+ "String_Node_Str");
  if (filterInQuery) {
    for (    Class<? extends OpenmrsData> clazz : patientJoinProperties.keySet()) {
      if (clazz.isAssignableFrom(type) && baseCohort != null) {
        hql.append("String_Node_Str" + alias + "String_Node_Str"+ patientJoinProperties.get(clazz)+ "String_Node_Str");
      }
    }
  }
  Query query=sessionFactory.getCurrentSession().createQuery(hql.toString());
  if (hql.toString().contains("String_Node_Str")) {
    query.setParameterList("String_Node_Str",baseCohort.getMemberIds());
  }
  for (  Object o : query.list()) {
    Object[] vals=(Object[])o;
    Integer ptId=(Integer)vals[0];
    if (doNotFilterInJava || baseCohort.contains(ptId)) {
      ret.put(ptId,vals[1]);
    }
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * @see DataSetQueryDAO#getPropertyValues(Class,String,EvaluationContext)
 */
public Map<Integer,Object> getPropertyValues(Class<? extends OpenmrsObject> type,String property,EvaluationContext context){
  Map<Integer,Object> ret=new HashMap<Integer,Object>();
  Cohort baseCohort=context.getBaseCohort();
  if (baseCohort != null && baseCohort.isEmpty()) {
    return ret;
  }
  ClassMetadata metadata=sessionFactory.getClassMetadata(type);
  String idPropertyName=metadata.getIdentifierPropertyName();
  String entityName=type.getSimpleName();
  String alias=entityName.toLowerCase();
  Map<Class<? extends OpenmrsData>,String> patientJoinProperties=new HashMap<Class<? extends OpenmrsData>,String>();
  patientJoinProperties.put(Person.class,"String_Node_Str");
  patientJoinProperties.put(Patient.class,"String_Node_Str");
  patientJoinProperties.put(Encounter.class,"String_Node_Str");
  patientJoinProperties.put(Obs.class,"String_Node_Str");
  patientJoinProperties.put(Order.class,"String_Node_Str");
  patientJoinProperties.put(PatientProgram.class,"String_Node_Str");
  patientJoinProperties.put(PatientState.class,"String_Node_Str");
  patientJoinProperties.put(PersonName.class,"String_Node_Str");
  patientJoinProperties.put(PatientIdentifier.class,"String_Node_Str");
  patientJoinProperties.put(Relationship.class,"String_Node_Str");
  String voidedProperty=(type == Person.class ? "String_Node_Str" : "String_Node_Str");
  boolean personOrPatientQuery=type.equals(Patient.class) || type.equals(Person.class);
  boolean filterInQuery=!personOrPatientQuery || (baseCohort != null && baseCohort.size() < 2000);
  boolean doNotFilterInJava=baseCohort == null || filterInQuery;
  StringBuilder hql=new StringBuilder();
  hql.append("String_Node_Str" + idPropertyName + "String_Node_Str"+ property+ "String_Node_Str");
  hql.append("String_Node_Str" + entityName + "String_Node_Str"+ alias+ "String_Node_Str");
  hql.append("String_Node_Str" + alias + "String_Node_Str"+ voidedProperty+ "String_Node_Str");
  if (filterInQuery) {
    for (    Class<? extends OpenmrsData> clazz : patientJoinProperties.keySet()) {
      if (clazz.isAssignableFrom(type) && baseCohort != null) {
        hql.append("String_Node_Str" + alias + "String_Node_Str"+ patientJoinProperties.get(clazz)+ "String_Node_Str");
      }
    }
  }
  Query query=sessionFactory.getCurrentSession().createQuery(hql.toString());
  if (hql.toString().contains("String_Node_Str")) {
    query.setParameterList("String_Node_Str",baseCohort.getMemberIds());
  }
  for (  Object o : query.list()) {
    Object[] vals=(Object[])o;
    Integer ptId=(Integer)vals[0];
    if (doNotFilterInJava || baseCohort.contains(ptId)) {
      ret.put(ptId,vals[1]);
    }
  }
  return ret;
}