Program: 64743
Project: 64743
Buggy source:
public static String stringifyId(Object entity,String typeName,PersistenceContext app){
  ClassDescriptor descriptor=app.getDescriptor(typeName);
  List<DatabaseMapping> pkMappings=descriptor.getObjectBuilder().getPrimaryKeyMappings();
  if (pkMappings.isEmpty()) {
    return "String_Node_Str";
  }
  List<SortableKey> pkIndices=new ArrayList<SortableKey>();
  int index=0;
  for (  DatabaseMapping mapping : pkMappings) {
    pkIndices.add(new SortableKey(mapping,index));
    index++;
  }
  Collections.sort(pkIndices);
  StringBuffer key=new StringBuffer();
  Iterator<SortableKey> sortableKeys=pkIndices.iterator();
  while (sortableKeys.hasNext()) {
    DatabaseMapping mapping=sortableKeys.next().getMapping();
    key.append(mapping.getAttributeValueFromObject(entity).toString());
    if (sortableKeys.hasNext()) {
      key.append(SEPARATOR_STRING);
    }
  }
  return key.toString();
}

Fixed version (ground truth):
public static String stringifyId(Object entity,String typeName,PersistenceContext app){
  ClassDescriptor descriptor=app.getDescriptor(typeName);
  List<DatabaseMapping> pkMappings=descriptor.getObjectBuilder().getPrimaryKeyMappings();
  if (pkMappings.isEmpty()) {
    return "String_Node_Str";
  }
  List<SortableKey> pkIndices=new ArrayList<SortableKey>();
  int index=0;
  for (  DatabaseMapping mapping : pkMappings) {
    pkIndices.add(new SortableKey(mapping,index));
    index++;
  }
  Collections.sort(pkIndices);
  StringBuffer key=new StringBuffer();
  Iterator<SortableKey> sortableKeys=pkIndices.iterator();
  List<DatabaseField> refObjectdbFields=null;
  while (sortableKeys.hasNext()) {
    DatabaseMapping mapping=sortableKeys.next().getMapping();
    ClassDescriptor refDesc=mapping.getReferenceDescriptor();
    List<DatabaseField> dbFields=mapping.getDescriptor().getPrimaryKeyFields();
    if (refDesc != null) {
      refObjectdbFields=refDesc.getFields();
    }
    if ((refObjectdbFields != null) && (!refObjectdbFields.isEmpty())) {
      for (      DatabaseField dbField : dbFields) {
        String dbFieldName=dbField.getName();
        String refObjectDbFieldName=null;
        if (refDesc != null) {
          for (          DatabaseField refObjectDbField : refObjectdbFields) {
            refObjectDbFieldName=refObjectDbField.getName();
            if ((refObjectDbFieldName != null) && (dbFieldName != null)) {
              if (dbFieldName.equals(refObjectDbFieldName)) {
                List<DatabaseMapping> refMappings=refDesc.getMappings();
                for (                DatabaseMapping refMapping : refMappings) {
                  String field=refMapping.getField().getName();
                  if ((field != null) && (dbFieldName.equals(field))) {
                    Object value=descriptor.getObjectBuilder().getBaseValueForField(dbField,entity);
                    Object realAttributeValue=refMapping.getRealAttributeValueFromAttribute(refMapping.getAttributeValueFromObject(value),value,app.getJpaSession());
                    key.append(realAttributeValue);
                  }
                }
              }
            }
          }
        }
      }
    }
 else {
      Object part=mapping.getAttributeValueFromObject(entity);
      key.append(part);
    }
    if (sortableKeys.hasNext()) {
      key.append(SEPARATOR_STRING);
      refObjectdbFields=null;
    }
  }
  return key.toString();
}