Program: 112330
Project: 112330
Buggy source:
private Set<Long> addPredicateToken(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<ResourceIndexedSearchParamToken> from=cq.from(ResourceIndexedSearchParamToken.class);
  cq.select(from.get("String_Node_Str").as(Long.class));
  List<Predicate> codePredicates=new ArrayList<Predicate>();
  for (  IQueryParameterType nextOr : theOrParams) {
    IQueryParameterType params=nextOr;
    String code;
    String system;
    if (params instanceof IdentifierDt) {
      IdentifierDt id=(IdentifierDt)params;
      system=id.getSystem().getValueAsString();
      code=id.getValue().getValue();
    }
 else     if (params instanceof CodingDt) {
      CodingDt id=(CodingDt)params;
      system=id.getSystem().getValueAsString();
      code=id.getCode().getValue();
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + params.getClass());
    }
    ArrayList<Predicate> singleCodePredicates=(new ArrayList<Predicate>());
    if (StringUtils.isNotBlank(system)) {
      singleCodePredicates.add(builder.equal(from.get("String_Node_Str"),system));
    }
 else {
      singleCodePredicates.add(builder.isNull(from.get("String_Node_Str")));
    }
    if (StringUtils.isNotBlank(code)) {
      singleCodePredicates.add(builder.equal(from.get("String_Node_Str"),code));
    }
 else {
      singleCodePredicates.add(builder.isNull(from.get("String_Node_Str")));
    }
    Predicate singleCode=builder.and(singleCodePredicates.toArray(new Predicate[0]));
    codePredicates.add(singleCode);
  }
  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> addPredicateToken(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<ResourceIndexedSearchParamToken> from=cq.from(ResourceIndexedSearchParamToken.class);
  cq.select(from.get("String_Node_Str").as(Long.class));
  List<Predicate> codePredicates=new ArrayList<Predicate>();
  for (  IQueryParameterType nextOr : theOrParams) {
    IQueryParameterType params=nextOr;
    String code;
    String system;
    if (params instanceof IdentifierDt) {
      IdentifierDt id=(IdentifierDt)params;
      system=id.getSystem().getValueAsString();
      code=id.getValue().getValue();
    }
 else     if (params instanceof CodingDt) {
      CodingDt id=(CodingDt)params;
      system=id.getSystem().getValueAsString();
      code=id.getCode().getValue();
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + params.getClass());
    }
    ArrayList<Predicate> singleCodePredicates=(new ArrayList<Predicate>());
    if (StringUtils.isNotBlank(system)) {
      singleCodePredicates.add(builder.equal(from.get("String_Node_Str"),system));
    }
 else {
      singleCodePredicates.add(builder.isNull(from.get("String_Node_Str")));
    }
    if (StringUtils.isNotBlank(code)) {
      singleCodePredicates.add(builder.equal(from.get("String_Node_Str"),code));
    }
 else {
      singleCodePredicates.add(builder.isNull(from.get("String_Node_Str")));
    }
    Predicate singleCode=builder.and(singleCodePredicates.toArray(new Predicate[0]));
    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());
}