Program: 112333
Project: 112333
Buggy source:
private Set<Long> addPredicateQuantity(Set<Long> thePids,List<IQueryParameterType> theOrParams){
  if (theOrParams == null || theOrParams.isEmpty()) {
    return thePids;
  }
  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 : theOrParams) {
    IQueryParameterType params=nextOr;
    if (params instanceof QuantityDt) {
      QuantityDt id=(QuantityDt)params;
      Predicate system;
      if (id.getSystem().isEmpty()) {
        system=builder.isNull(from.get("String_Node_Str"));
      }
 else {
        system=builder.equal(from.get("String_Node_Str"),id.getSystem().getValueAsString());
      }
      Predicate code;
      if (id.getCode().isEmpty()) {
        code=builder.isNull(from.get("String_Node_Str"));
      }
 else {
        code=builder.equal(from.get("String_Node_Str"),id.getUnits().getValueAsString());
      }
      Predicate num;
      if (id.getComparator().getValueAsEnum() == null) {
        num=builder.equal(from.get("String_Node_Str"),id.getValue().getValue());
      }
 else {
switch (id.getComparator().getValueAsEnum()) {
case GREATERTHAN:
          Expression<Number> path=from.get("String_Node_Str");
        Number value=id.getValue().getValue();
      num=builder.gt(path,value);
    break;
case GREATERTHAN_OR_EQUALS:
  path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.ge(path,value);
break;
case LESSTHAN:
path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.lt(path,value);
break;
case LESSTHAN_OR_EQUALS:
path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.le(path,value);
break;
default :
throw new IllegalStateException(id.getComparator().getValueAsString());
}
}
Predicate singleCode=builder.and(system,code,num);
codePredicates.add(singleCode);
}
 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);
if (thePids.size() > 0) {
Predicate inPids=(from.get("String_Node_Str").in(thePids));
cq.where(builder.and(type,inPids,masterCodePredicate));
}
 else {
cq.where(builder.and(type,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<IQueryParameterType> theOrParams){
  if (theOrParams == null || theOrParams.isEmpty()) {
    return thePids;
  }
  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 : theOrParams) {
    IQueryParameterType params=nextOr;
    if (params instanceof QuantityDt) {
      QuantityDt id=(QuantityDt)params;
      Predicate system;
      if (id.getSystem().isEmpty()) {
        system=builder.isNull(from.get("String_Node_Str"));
      }
 else {
        system=builder.equal(from.get("String_Node_Str"),id.getSystem().getValueAsString());
      }
      Predicate code;
      if (id.getCode().isEmpty()) {
        code=builder.isNull(from.get("String_Node_Str"));
      }
 else {
        code=builder.equal(from.get("String_Node_Str"),id.getUnits().getValueAsString());
      }
      Predicate num;
      if (id.getComparator().getValueAsEnum() == null) {
        num=builder.equal(from.get("String_Node_Str"),id.getValue().getValue());
      }
 else {
switch (id.getComparator().getValueAsEnum()) {
case GREATERTHAN:
          Expression<Number> path=from.get("String_Node_Str");
        Number value=id.getValue().getValue();
      num=builder.gt(path,value);
    break;
case GREATERTHAN_OR_EQUALS:
  path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.ge(path,value);
break;
case LESSTHAN:
path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.lt(path,value);
break;
case LESSTHAN_OR_EQUALS:
path=from.get("String_Node_Str");
value=id.getValue().getValue();
num=builder.le(path,value);
break;
default :
throw new IllegalStateException(id.getComparator().getValueAsString());
}
}
Predicate singleCode=builder.and(system,code,num);
codePredicates.add(singleCode);
}
 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());
}