Program: 84555
Project: 84555
Buggy source:
/** 
 * Uses reflection to translate a PatientSearch into a PatientFilter
 */
@SuppressWarnings("String_Node_Str") public static PatientFilter toPatientFilter(PatientSearch search,CohortSearchHistory history,EvaluationContext evalContext){
  if (search.isSavedSearchReference()) {
    PatientSearch ps=((PatientSearchReportObject)Context.getReportObjectService().getReportObject(search.getSavedSearchId())).getPatientSearch();
    return toPatientFilter(ps,history,evalContext);
  }
 else   if (search.isSavedFilterReference()) {
    return Context.getReportObjectService().getPatientFilterById(search.getSavedFilterId());
  }
 else   if (search.isSavedCohortReference()) {
    Cohort c=Context.getCohortService().getCohort(search.getSavedCohortId());
    if (c != null)     c.getMemberIds().size();
    return new CohortFilter(c);
  }
 else   if (search.isComposition()) {
    if (history == null && search.requiresHistory())     throw new IllegalArgumentException("String_Node_Str");
 else     return search.cloneCompositionAsFilter(history,evalContext);
  }
 else {
    Class clz=search.getFilterClass();
    if (clz == null)     throw new IllegalArgumentException("String_Node_Str");
    log.debug("String_Node_Str" + clz);
    PatientFilter pf=null;
    try {
      pf=(PatientFilter)clz.newInstance();
    }
 catch (    Exception ex) {
      log.error("String_Node_Str" + search.getFilterClass(),ex);
      return null;
    }
    Class[] stringSingleton={String.class};
    if (search.getArguments() != null) {
      for (      SearchArgument sa : search.getArguments()) {
        if (log.isDebugEnabled())         log.debug("String_Node_Str" + sa.getPropertyClass() + "String_Node_Str"+ sa.getName()+ "String_Node_Str"+ sa.getValue());
        PropertyDescriptor pd=null;
        try {
          pd=new PropertyDescriptor(sa.getName(),clz);
        }
 catch (        IntrospectionException ex) {
          log.error("String_Node_Str" + sa.getName(),ex);
          continue;
        }
        Class<?> realPropertyType=pd.getPropertyType();
        String valueAsString=sa.getValue();
        String testForExpression=search.getArgumentValue(sa.getName());
        if (evalContext != null && EvaluationContext.isExpression(testForExpression)) {
          log.debug("String_Node_Str" + testForExpression);
          Object evaluated=evalContext.evaluateExpression(testForExpression);
          if (evaluated != null) {
            if (evaluated instanceof Date)             valueAsString=Context.getDateFormat().format((Date)evaluated);
 else             valueAsString=evaluated.toString();
          }
          log.debug("String_Node_Str" + valueAsString);
        }
        Object value=null;
        Class<?> valueClass=sa.getPropertyClass();
        try {
          Method valueOfMethod=null;
          try {
            valueOfMethod=valueClass.getMethod("String_Node_Str",stringSingleton);
          }
 catch (          NoSuchMethodException ex) {
          }
          if (valueOfMethod != null) {
            Object[] holder={valueAsString};
            value=valueOfMethod.invoke(pf,holder);
          }
 else           if (realPropertyType.isEnum()) {
            List<Enum> constants=Arrays.asList((Enum[])realPropertyType.getEnumConstants());
            for (            Enum e : constants) {
              if (e.toString().equals(valueAsString)) {
                value=e;
                break;
              }
            }
          }
 else           if (String.class.equals(valueClass)) {
            value=valueAsString;
          }
 else           if (Location.class.equals(valueClass)) {
            LocationEditor ed=new LocationEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Concept.class.equals(valueClass)) {
            ConceptEditor ed=new ConceptEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Program.class.equals(valueClass)) {
            ProgramEditor ed=new ProgramEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (ProgramWorkflowState.class.equals(valueClass)) {
            ProgramWorkflowStateEditor ed=new ProgramWorkflowStateEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (EncounterType.class.equals(valueClass)) {
            EncounterTypeEditor ed=new EncounterTypeEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Form.class.equals(valueClass)) {
            FormEditor ed=new FormEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Drug.class.equals(valueClass)) {
            DrugEditor ed=new DrugEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (PersonAttributeType.class.equals(valueClass)) {
            PersonAttributeTypeEditor ed=new PersonAttributeTypeEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Cohort.class.equals(valueClass)) {
            CohortEditor ed=new CohortEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Date.class.equals(valueClass)) {
            DateFormat df=Context.getDateFormat();
            CustomDateEditor ed=new CustomDateEditor(df,true,10);
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (LogicCriteria.class.equals(valueClass)) {
            value=Context.getLogicService().parseString(valueAsString);
          }
 else {
            value=valueAsString;
          }
        }
 catch (        Exception ex) {
          log.error("String_Node_Str" + valueAsString + "String_Node_Str"+ valueClass,ex);
          continue;
        }
        if (value != null) {
          if (realPropertyType.isAssignableFrom(valueClass)) {
            log.debug("String_Node_Str" + sa.getName() + "String_Node_Str"+ value);
            try {
              pd.getWriteMethod().invoke(pf,value);
            }
 catch (            Exception ex) {
              log.error("String_Node_Str" + sa.getName() + "String_Node_Str"+ sa.getValue()+ "String_Node_Str"+ value,ex);
              continue;
            }
          }
 else           if (Collection.class.isAssignableFrom(realPropertyType)) {
            log.debug(sa.getName() + "String_Node_Str");
            try {
              Collection collection=(Collection)pd.getReadMethod().invoke(pf,(Object[])null);
              if (collection == null) {
                if (SortedSet.class.isAssignableFrom(realPropertyType)) {
                  collection=new TreeSet();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
 else                 if (Set.class.isAssignableFrom(realPropertyType)) {
                  collection=new HashSet();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
 else {
                  collection=new ArrayList();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
              }
              collection.add(value);
            }
 catch (            Exception ex) {
              log.error("String_Node_Str" + sa.getName() + "String_Node_Str"+ realPropertyType,ex);
              continue;
            }
          }
 else {
            log.error(pf.getClass() + "String_Node_Str" + sa.getName()+ "String_Node_Str"+ realPropertyType+ "String_Node_Str"+ valueClass);
          }
        }
      }
    }
    log.debug("String_Node_Str" + pf);
    return pf;
  }
}

Fixed version (ground truth):
/** 
 * Uses reflection to translate a PatientSearch into a PatientFilter
 */
@SuppressWarnings("String_Node_Str") public static PatientFilter toPatientFilter(PatientSearch search,CohortSearchHistory history,EvaluationContext evalContext){
  if (search.isSavedSearchReference()) {
    PatientSearch ps=((PatientSearchReportObject)Context.getReportObjectService().getReportObject(search.getSavedSearchId())).getPatientSearch();
    return toPatientFilter(ps,history,evalContext);
  }
 else   if (search.isSavedFilterReference()) {
    return Context.getReportObjectService().getPatientFilterById(search.getSavedFilterId());
  }
 else   if (search.isSavedCohortReference()) {
    Cohort c=Context.getCohortService().getCohort(search.getSavedCohortId());
    if (c != null)     c.getMemberIds().size();
    return new CohortFilter(c);
  }
 else   if (search.isComposition()) {
    if (history == null && search.requiresHistory())     throw new IllegalArgumentException("String_Node_Str");
 else     return search.cloneCompositionAsFilter(history,evalContext);
  }
 else {
    Class clz=search.getFilterClass();
    if (clz == null)     throw new IllegalArgumentException("String_Node_Str");
    log.debug("String_Node_Str" + clz);
    PatientFilter pf=null;
    try {
      pf=(PatientFilter)clz.newInstance();
    }
 catch (    Exception ex) {
      log.error("String_Node_Str" + search.getFilterClass(),ex);
      return null;
    }
    Class[] stringSingleton={String.class};
    if (search.getArguments() != null) {
      for (      SearchArgument sa : search.getArguments()) {
        if (log.isDebugEnabled())         log.debug("String_Node_Str" + sa.getPropertyClass() + "String_Node_Str"+ sa.getName()+ "String_Node_Str"+ sa.getValue());
        PropertyDescriptor pd=null;
        try {
          pd=new PropertyDescriptor(sa.getName(),clz);
        }
 catch (        IntrospectionException ex) {
          log.error("String_Node_Str" + sa.getName(),ex);
          continue;
        }
        Class<?> realPropertyType=pd.getPropertyType();
        String valueAsString=sa.getValue();
        String testForExpression=search.getArgumentValue(sa.getName());
        if (testForExpression != null) {
          valueAsString=testForExpression;
          log.debug("String_Node_Str" + sa.getName() + "String_Node_Str"+ valueAsString);
          if (evalContext != null && EvaluationContext.isExpression(valueAsString)) {
            Object evaluated=evalContext.evaluateExpression(testForExpression);
            if (evaluated != null) {
              if (evaluated instanceof Date)               valueAsString=Context.getDateFormat().format((Date)evaluated);
 else               valueAsString=evaluated.toString();
            }
            log.debug("String_Node_Str" + sa.getName() + "String_Node_Str"+ valueAsString);
          }
        }
        Object value=null;
        Class<?> valueClass=sa.getPropertyClass();
        try {
          Method valueOfMethod=null;
          try {
            valueOfMethod=valueClass.getMethod("String_Node_Str",stringSingleton);
          }
 catch (          NoSuchMethodException ex) {
          }
          if (valueOfMethod != null) {
            Object[] holder={valueAsString};
            value=valueOfMethod.invoke(pf,holder);
          }
 else           if (realPropertyType.isEnum()) {
            List<Enum> constants=Arrays.asList((Enum[])realPropertyType.getEnumConstants());
            for (            Enum e : constants) {
              if (e.toString().equals(valueAsString)) {
                value=e;
                break;
              }
            }
          }
 else           if (String.class.equals(valueClass)) {
            value=valueAsString;
          }
 else           if (Location.class.equals(valueClass)) {
            LocationEditor ed=new LocationEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Concept.class.equals(valueClass)) {
            ConceptEditor ed=new ConceptEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Program.class.equals(valueClass)) {
            ProgramEditor ed=new ProgramEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (ProgramWorkflowState.class.equals(valueClass)) {
            ProgramWorkflowStateEditor ed=new ProgramWorkflowStateEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (EncounterType.class.equals(valueClass)) {
            EncounterTypeEditor ed=new EncounterTypeEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Form.class.equals(valueClass)) {
            FormEditor ed=new FormEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Drug.class.equals(valueClass)) {
            DrugEditor ed=new DrugEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (PersonAttributeType.class.equals(valueClass)) {
            PersonAttributeTypeEditor ed=new PersonAttributeTypeEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Cohort.class.equals(valueClass)) {
            CohortEditor ed=new CohortEditor();
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (Date.class.equals(valueClass)) {
            DateFormat df=Context.getDateFormat();
            CustomDateEditor ed=new CustomDateEditor(df,true,10);
            ed.setAsText(valueAsString);
            value=ed.getValue();
          }
 else           if (LogicCriteria.class.equals(valueClass)) {
            value=Context.getLogicService().parseString(valueAsString);
          }
 else {
            value=valueAsString;
          }
        }
 catch (        Exception ex) {
          log.error("String_Node_Str" + valueAsString + "String_Node_Str"+ valueClass,ex);
          continue;
        }
        if (value != null) {
          if (realPropertyType.isAssignableFrom(valueClass)) {
            log.debug("String_Node_Str" + sa.getName() + "String_Node_Str"+ value);
            try {
              pd.getWriteMethod().invoke(pf,value);
            }
 catch (            Exception ex) {
              log.error("String_Node_Str" + sa.getName() + "String_Node_Str"+ sa.getValue()+ "String_Node_Str"+ value,ex);
              continue;
            }
          }
 else           if (Collection.class.isAssignableFrom(realPropertyType)) {
            log.debug(sa.getName() + "String_Node_Str");
            try {
              Collection collection=(Collection)pd.getReadMethod().invoke(pf,(Object[])null);
              if (collection == null) {
                if (SortedSet.class.isAssignableFrom(realPropertyType)) {
                  collection=new TreeSet();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
 else                 if (Set.class.isAssignableFrom(realPropertyType)) {
                  collection=new HashSet();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
 else {
                  collection=new ArrayList();
                  log.debug("String_Node_Str");
                  pd.getWriteMethod().invoke(pf,collection);
                }
              }
              collection.add(value);
            }
 catch (            Exception ex) {
              log.error("String_Node_Str" + sa.getName() + "String_Node_Str"+ realPropertyType,ex);
              continue;
            }
          }
 else {
            log.error(pf.getClass() + "String_Node_Str" + sa.getName()+ "String_Node_Str"+ realPropertyType+ "String_Node_Str"+ valueClass);
          }
        }
      }
    }
    log.debug("String_Node_Str" + pf);
    return pf;
  }
}