Program: 112304
Project: 112304
Buggy source:
private Set<Long> addPredicateNumber(String theParamName,Set<Long> thePids,List<? extends IQueryParameterType> theList){
  if (theList == null || theList.isEmpty()) {
    return thePids;
  }
  if (Boolean.TRUE.equals(theList.get(0).getMissing())) {
    return addPredicateParamMissing(thePids,"String_Node_Str");
  }
  CriteriaBuilder builder=myEntityManager.getCriteriaBuilder();
  CriteriaQuery<Long> cq=builder.createQuery(Long.class);
  Root<ResourceIndexedSearchParamNumber> from=cq.from(ResourceIndexedSearchParamNumber.class);
  cq.select(from.get("String_Node_Str").as(Long.class));
  List<Predicate> codePredicates=new ArrayList<Predicate>();
  for (  IQueryParameterType nextOr : theList) {
    IQueryParameterType params=nextOr;
    if (addPredicateMissingFalseIfPresent(theParamName,from,codePredicates,nextOr)) {
      continue;
    }
    if (params instanceof NumberParam) {
      NumberParam param=(NumberParam)params;
      BigDecimal value=param.getValue();
      if (value == null) {
        return thePids;
      }
      Path<Object> fromObj=from.get("String_Node_Str");
      if (param.getComparator() == null) {
        double mul=value.doubleValue() * 1.01;
        double low=value.doubleValue() - mul;
        double high=value.doubleValue() + mul;
        Predicate lowPred=builder.ge(fromObj.as(Long.class),low);
        Predicate highPred=builder.le(fromObj.as(Long.class),high);
        codePredicates.add(builder.and(lowPred,highPred));
      }
 else {
switch (param.getComparator()) {
case GREATERTHAN:
          codePredicates.add(builder.greaterThan(fromObj.as(BigDecimal.class),value));
        break;
case GREATERTHAN_OR_EQUALS:
      codePredicates.add(builder.ge(fromObj.as(BigDecimal.class),value));
    break;
case LESSTHAN:
  codePredicates.add(builder.lessThan(fromObj.as(BigDecimal.class),value));
break;
case LESSTHAN_OR_EQUALS:
codePredicates.add(builder.le(fromObj.as(BigDecimal.class),value));
break;
}
}
}
 else {
throw new IllegalArgumentException("String_Node_Str" + params.getClass());
}
}
Predicate masterCodePredicate=builder.or(codePredicates.toArray(new Predicate[0]));
Predicate type=builder.equal(from.get("String_Node_Str"),myResourceName);
Predicate name=builder.equal(from.get("String_Node_Str"),theParamName);
if (thePids.size() > 0) {
Predicate inPids=(from.get("String_Node_Str").in(thePids));
cq.where(builder.and(type,name,masterCodePredicate,inPids));
}
 else {
cq.where(builder.and(type,name,masterCodePredicate));
}
TypedQuery<Long> q=myEntityManager.createQuery(cq);
return new HashSet<Long>(q.getResultList());
}

Fixed version (ground truth):
private Set<Long> addPredicateNumber(String theParamName,Set<Long> thePids,List<? extends IQueryParameterType> theList){
  if (theList == null || theList.isEmpty()) {
    return thePids;
  }
  if (Boolean.TRUE.equals(theList.get(0).getMissing())) {
    return addPredicateParamMissing(thePids,"String_Node_Str",theParamName,ResourceIndexedSearchParamNumber.class);
  }
  CriteriaBuilder builder=myEntityManager.getCriteriaBuilder();
  CriteriaQuery<Long> cq=builder.createQuery(Long.class);
  Root<ResourceIndexedSearchParamNumber> from=cq.from(ResourceIndexedSearchParamNumber.class);
  cq.select(from.get("String_Node_Str").as(Long.class));
  List<Predicate> codePredicates=new ArrayList<Predicate>();
  for (  IQueryParameterType nextOr : theList) {
    IQueryParameterType params=nextOr;
    if (addPredicateMissingFalseIfPresent(builder,theParamName,from,codePredicates,nextOr)) {
      continue;
    }
    if (params instanceof NumberParam) {
      NumberParam param=(NumberParam)params;
      BigDecimal value=param.getValue();
      if (value == null) {
        return thePids;
      }
      Path<Object> fromObj=from.get("String_Node_Str");
      if (param.getComparator() == null) {
        double mul=value.doubleValue() * 1.01;
        double low=value.doubleValue() - mul;
        double high=value.doubleValue() + mul;
        Predicate lowPred=builder.ge(fromObj.as(Long.class),low);
        Predicate highPred=builder.le(fromObj.as(Long.class),high);
        codePredicates.add(builder.and(lowPred,highPred));
      }
 else {
switch (param.getComparator()) {
case GREATERTHAN:
          codePredicates.add(builder.greaterThan(fromObj.as(BigDecimal.class),value));
        break;
case GREATERTHAN_OR_EQUALS:
      codePredicates.add(builder.ge(fromObj.as(BigDecimal.class),value));
    break;
case LESSTHAN:
  codePredicates.add(builder.lessThan(fromObj.as(BigDecimal.class),value));
break;
case LESSTHAN_OR_EQUALS:
codePredicates.add(builder.le(fromObj.as(BigDecimal.class),value));
break;
}
}
}
 else {
throw new IllegalArgumentException("String_Node_Str" + params.getClass());
}
}
Predicate masterCodePredicate=builder.or(codePredicates.toArray(new Predicate[0]));
Predicate type=builder.equal(from.get("String_Node_Str"),myResourceName);
Predicate name=builder.equal(from.get("String_Node_Str"),theParamName);
if (thePids.size() > 0) {
Predicate inPids=(from.get("String_Node_Str").in(thePids));
cq.where(builder.and(type,name,masterCodePredicate,inPids));
}
 else {
cq.where(builder.and(type,name,masterCodePredicate));
}
TypedQuery<Long> q=myEntityManager.createQuery(cq);
return new HashSet<Long>(q.getResultList());
}