Program: 112307
Project: 112307
Buggy source:
private Set<Long> addPredicateQuantity(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<ResourceIndexedSearchParamQuantity> from=cq.from(ResourceIndexedSearchParamQuantity.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;
    }
    String systemValue;
    String unitsValue;
    QuantityCompararatorEnum cmpValue;
    BigDecimal valueValue;
    boolean approx=false;
    if (params instanceof BaseQuantityDt) {
      BaseQuantityDt param=(BaseQuantityDt)params;
      systemValue=param.getSystemElement().getValueAsString();
      unitsValue=param.getUnitsElement().getValueAsString();
      cmpValue=QuantityCompararatorEnum.VALUESET_BINDER.fromCodeString(param.getComparatorElement().getValueAsString());
      valueValue=param.getValueElement().getValue();
    }
 else     if (params instanceof QuantityParam) {
      QuantityParam param=(QuantityParam)params;
      systemValue=param.getSystem().getValueAsString();
      unitsValue=param.getUnits();
      cmpValue=param.getComparator();
      valueValue=param.getValue().getValue();
      approx=param.isApproximate();
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + params.getClass());
    }
    Predicate system=null;
    if (!isBlank(systemValue)) {
      system=builder.equal(from.get("String_Node_Str"),systemValue);
    }
    Predicate code=null;
    if (!isBlank(unitsValue)) {
      code=builder.equal(from.get("String_Node_Str"),unitsValue);
    }
    Predicate num;
    if (cmpValue == null) {
      BigDecimal mul=approx ? new BigDecimal(0.1) : new BigDecimal(0.01);
      BigDecimal low=valueValue.subtract(valueValue.multiply(mul));
      BigDecimal high=valueValue.add(valueValue.multiply(mul));
      Predicate lowPred=builder.gt(from.get("String_Node_Str").as(BigDecimal.class),low);
      Predicate highPred=builder.lt(from.get("String_Node_Str").as(BigDecimal.class),high);
      num=builder.and(lowPred,highPred);
    }
 else {
switch (cmpValue) {
case GREATERTHAN:
        Expression<Number> path=from.get("String_Node_Str");
      num=builder.gt(path,valueValue);
    break;
case GREATERTHAN_OR_EQUALS:
  path=from.get("String_Node_Str");
num=builder.ge(path,valueValue);
break;
case LESSTHAN:
path=from.get("String_Node_Str");
num=builder.lt(path,valueValue);
break;
case LESSTHAN_OR_EQUALS:
path=from.get("String_Node_Str");
num=builder.le(path,valueValue);
break;
default :
throw new IllegalStateException(cmpValue.getCode());
}
}
if (system == null && code == null) {
codePredicates.add(num);
}
 else if (system == null) {
Predicate singleCode=builder.and(code,num);
codePredicates.add(singleCode);
}
 else if (code == null) {
Predicate singleCode=builder.and(system,num);
codePredicates.add(singleCode);
}
 else {
Predicate singleCode=builder.and(system,code,num);
codePredicates.add(singleCode);
}
}
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> addPredicateQuantity(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,ResourceIndexedSearchParamQuantity.class);
  }
  CriteriaBuilder builder=myEntityManager.getCriteriaBuilder();
  CriteriaQuery<Long> cq=builder.createQuery(Long.class);
  Root<ResourceIndexedSearchParamQuantity> from=cq.from(ResourceIndexedSearchParamQuantity.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;
    }
    String systemValue;
    String unitsValue;
    QuantityCompararatorEnum cmpValue;
    BigDecimal valueValue;
    boolean approx=false;
    if (params instanceof BaseQuantityDt) {
      BaseQuantityDt param=(BaseQuantityDt)params;
      systemValue=param.getSystemElement().getValueAsString();
      unitsValue=param.getUnitsElement().getValueAsString();
      cmpValue=QuantityCompararatorEnum.VALUESET_BINDER.fromCodeString(param.getComparatorElement().getValueAsString());
      valueValue=param.getValueElement().getValue();
    }
 else     if (params instanceof QuantityParam) {
      QuantityParam param=(QuantityParam)params;
      systemValue=param.getSystem().getValueAsString();
      unitsValue=param.getUnits();
      cmpValue=param.getComparator();
      valueValue=param.getValue().getValue();
      approx=param.isApproximate();
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + params.getClass());
    }
    Predicate system=null;
    if (!isBlank(systemValue)) {
      system=builder.equal(from.get("String_Node_Str"),systemValue);
    }
    Predicate code=null;
    if (!isBlank(unitsValue)) {
      code=builder.equal(from.get("String_Node_Str"),unitsValue);
    }
    Predicate num;
    if (cmpValue == null) {
      BigDecimal mul=approx ? new BigDecimal(0.1) : new BigDecimal(0.01);
      BigDecimal low=valueValue.subtract(valueValue.multiply(mul));
      BigDecimal high=valueValue.add(valueValue.multiply(mul));
      Predicate lowPred=builder.gt(from.get("String_Node_Str").as(BigDecimal.class),low);
      Predicate highPred=builder.lt(from.get("String_Node_Str").as(BigDecimal.class),high);
      num=builder.and(lowPred,highPred);
    }
 else {
switch (cmpValue) {
case GREATERTHAN:
        Expression<Number> path=from.get("String_Node_Str");
      num=builder.gt(path,valueValue);
    break;
case GREATERTHAN_OR_EQUALS:
  path=from.get("String_Node_Str");
num=builder.ge(path,valueValue);
break;
case LESSTHAN:
path=from.get("String_Node_Str");
num=builder.lt(path,valueValue);
break;
case LESSTHAN_OR_EQUALS:
path=from.get("String_Node_Str");
num=builder.le(path,valueValue);
break;
default :
throw new IllegalStateException(cmpValue.getCode());
}
}
if (system == null && code == null) {
codePredicates.add(num);
}
 else if (system == null) {
Predicate singleCode=builder.and(code,num);
codePredicates.add(singleCode);
}
 else if (code == null) {
Predicate singleCode=builder.and(system,num);
codePredicates.add(singleCode);
}
 else {
Predicate singleCode=builder.and(system,code,num);
codePredicates.add(singleCode);
}
}
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());
}