Program: 64610
Project: 64610
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();
  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) {
                  DatabaseField field=refMapping.getField();
                  if (field != null) {
                    String fieldName=field.getName();
                    if (mapping instanceof OneToOneMapping) {
                      Map<DatabaseField,DatabaseField> targetToSourceKeyFields=((OneToOneMapping)mapping).getTargetToSourceKeyFields();
                      Map<DatabaseField,DatabaseField> sourceToTargetFields=((OneToOneMapping)mapping).getTargetToSourceKeyFields();
                      if ((targetToSourceKeyFields != null) && (!targetToSourceKeyFields.isEmpty())) {
                        if (targetToSourceKeyFields.containsKey(refObjectDbField)) {
                          if ((sourceToTargetFields != null) && (!sourceToTargetFields.isEmpty())) {
                            if (sourceToTargetFields.containsKey(field)) {
                              if ((fieldName != null) && (dbFieldName.equals(fieldName))) {
                                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();
}

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) {
                  DatabaseField field=refMapping.getField();
                  if (field != null) {
                    String fieldName=field.getName();
                    if (mapping instanceof OneToOneMapping) {
                      Map<DatabaseField,DatabaseField> targetToSourceKeyFields=((OneToOneMapping)mapping).getTargetToSourceKeyFields();
                      Map<DatabaseField,DatabaseField> sourceToTargetFields=((OneToOneMapping)mapping).getTargetToSourceKeyFields();
                      if ((targetToSourceKeyFields != null) && (!targetToSourceKeyFields.isEmpty())) {
                        if (targetToSourceKeyFields.containsKey(refObjectDbField)) {
                          if ((sourceToTargetFields != null) && (!sourceToTargetFields.isEmpty())) {
                            if (sourceToTargetFields.containsKey(field)) {
                              if ((fieldName != null) && (dbFieldName.equals(fieldName))) {
                                Object value=descriptor.getObjectBuilder().getBaseValueForField(dbField,entity);
                                Object realAttributeValue=refMapping.getRealAttributeValueFromAttribute(refMapping.getAttributeValueFromObject(value),value,(AbstractSession)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();
}