Program: 112292
Project: 112292
Buggy source:
private void createSort(CriteriaBuilder theBuilder,Root<ResourceTable> theFrom,SortSpec theSort,List<Order> theOrders,List<Predicate> thePredicates){
  if (theSort == null || isBlank(theSort.getParamName())) {
    return;
  }
  if ("String_Node_Str".equals(theSort.getParamName())) {
    From<?,?> forcedIdJoin=theFrom.join("String_Node_Str",JoinType.LEFT);
    if (theSort.getOrder() == null || theSort.getOrder() == SortOrderEnum.ASC) {
      theOrders.add(theBuilder.asc(forcedIdJoin.get("String_Node_Str")));
      theOrders.add(theBuilder.asc(theFrom.get("String_Node_Str")));
    }
 else {
      theOrders.add(theBuilder.desc(forcedIdJoin.get("String_Node_Str")));
      theOrders.add(theBuilder.desc(theFrom.get("String_Node_Str")));
    }
    createSort(theBuilder,theFrom,theSort.getChain(),theOrders,thePredicates);
    return;
  }
  RuntimeResourceDefinition resourceDef=getContext().getResourceDefinition(myResourceType);
  RuntimeSearchParam param=resourceDef.getSearchParam(theSort.getParamName());
  if (param == null) {
    throw new InvalidRequestException("String_Node_Str" + theSort.getParamName() + "String_Node_Str");
  }
  String joinAttrName;
  String sortAttrName;
switch (param.getParamType()) {
case STRING:
    joinAttrName="String_Node_Str";
  sortAttrName="String_Node_Str";
break;
case DATE:
joinAttrName="String_Node_Str";
sortAttrName="String_Node_Str";
break;
case REFERENCE:
joinAttrName="String_Node_Str";
sortAttrName="String_Node_Str";
break;
default :
throw new NotImplementedException("String_Node_Str" + param.getParamType() + "String_Node_Str"+ theSort.getParamName());
}
From<?,?> stringJoin=theFrom.join(joinAttrName,JoinType.INNER);
thePredicates.add(theBuilder.equal(stringJoin.get("String_Node_Str"),theSort.getParamName()));
if (theSort.getOrder() == null || theSort.getOrder() == SortOrderEnum.ASC) {
theOrders.add(theBuilder.asc(stringJoin.get(sortAttrName)));
}
 else {
theOrders.add(theBuilder.desc(stringJoin.get(sortAttrName)));
}
createSort(theBuilder,theFrom,theSort.getChain(),theOrders,thePredicates);
}

Fixed version (ground truth):
private void createSort(CriteriaBuilder theBuilder,Root<ResourceTable> theFrom,SortSpec theSort,List<Order> theOrders,List<Predicate> thePredicates){
  if (theSort == null || isBlank(theSort.getParamName())) {
    return;
  }
  if ("String_Node_Str".equals(theSort.getParamName())) {
    From<?,?> forcedIdJoin=theFrom.join("String_Node_Str",JoinType.LEFT);
    if (theSort.getOrder() == null || theSort.getOrder() == SortOrderEnum.ASC) {
      theOrders.add(theBuilder.asc(forcedIdJoin.get("String_Node_Str")));
      theOrders.add(theBuilder.asc(theFrom.get("String_Node_Str")));
    }
 else {
      theOrders.add(theBuilder.desc(forcedIdJoin.get("String_Node_Str")));
      theOrders.add(theBuilder.desc(theFrom.get("String_Node_Str")));
    }
    createSort(theBuilder,theFrom,theSort.getChain(),theOrders,thePredicates);
    return;
  }
  RuntimeResourceDefinition resourceDef=getContext().getResourceDefinition(myResourceType);
  RuntimeSearchParam param=resourceDef.getSearchParam(theSort.getParamName());
  if (param == null) {
    throw new InvalidRequestException("String_Node_Str" + theSort.getParamName() + "String_Node_Str");
  }
  String joinAttrName;
  String sortAttrName;
switch (param.getParamType()) {
case STRING:
    joinAttrName="String_Node_Str";
  sortAttrName="String_Node_Str";
break;
case DATE:
joinAttrName="String_Node_Str";
sortAttrName="String_Node_Str";
break;
case REFERENCE:
joinAttrName="String_Node_Str";
sortAttrName="String_Node_Str";
break;
default :
throw new NotImplementedException("String_Node_Str" + param.getParamType() + "String_Node_Str"+ theSort.getParamName());
}
From<?,?> stringJoin=theFrom.join(joinAttrName,JoinType.INNER);
if (param.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
thePredicates.add(stringJoin.get("String_Node_Str").as(String.class).in(param.getPathsSplit()));
}
 else {
thePredicates.add(theBuilder.equal(stringJoin.get("String_Node_Str"),theSort.getParamName()));
}
if (theSort.getOrder() == null || theSort.getOrder() == SortOrderEnum.ASC) {
theOrders.add(theBuilder.asc(stringJoin.get(sortAttrName)));
}
 else {
theOrders.add(theBuilder.desc(stringJoin.get(sortAttrName)));
}
createSort(theBuilder,theFrom,theSort.getChain(),theOrders,thePredicates);
}