Program: 62309
Project: 62309
Buggy source:
/** 
 * This utility method returns an ordered   {@link alien4cloud.model.components.IndexedInheritableToscaElement} collection. The parent elements will be beforethe children elements This utility method returns an ordered  {@link IndexedInheritableToscaElement} collection. The parent elements will be before the children elements
 * @param elementsByIdMap map of {@link IndexedInheritableToscaElement} by id
 * @return
 */
public static <T extends IndexedInheritableToscaElement>List<T> orderByDerivedFromHierarchy(final Map<String,T> elementsByIdMap){
  if (elementsByIdMap == null) {
    return null;
  }
  List<T> orderedElements=new ArrayList<T>(elementsByIdMap.values());
  final Map<String,Integer> elementsLevelMap=Maps.newHashMap();
  for (  IndexedInheritableToscaElement element : orderedElements) {
    IndexedInheritableToscaElement parent=element;
    int levelCount=0;
    while (true) {
      if (parent.getDerivedFrom() == null || parent.getDerivedFrom().isEmpty()) {
        break;
      }
      IndexedInheritableToscaElement oldParent=parent;
      parent=elementsByIdMap.get(parent.getDerivedFrom().get(0));
      if (parent == null) {
        break;
      }
      if (oldParent.equals(parent)) {
        throw new IndexingServiceException(parent.getElementId() + "String_Node_Str");
      }
      levelCount++;
    }
    elementsLevelMap.put(element.getElementId(),levelCount);
  }
  Collections.sort(orderedElements,new Comparator<IndexedInheritableToscaElement>(){
    @Override public int compare(    IndexedInheritableToscaElement left,    IndexedInheritableToscaElement right){
      return elementsLevelMap.get(left.getElementId()).compareTo(elementsLevelMap.get(right.getElementId()));
    }
  }
);
  return orderedElements;
}

Fixed version (ground truth):
/** 
 * This utility method returns an ordered   {@link alien4cloud.model.components.IndexedInheritableToscaElement} collection. The parent elements will be beforethe children elements This utility method returns an ordered  {@link IndexedInheritableToscaElement} collection. The parent elements will be before the children elements
 * @param elementsByIdMap map of {@link IndexedInheritableToscaElement} by id
 * @return
 */
public static <T extends IndexedInheritableToscaElement>List<T> orderByDerivedFromHierarchy(final Map<String,T> elementsByIdMap){
  if (elementsByIdMap == null) {
    return null;
  }
  List<T> orderedElements=new ArrayList<T>(elementsByIdMap.values());
  final Map<String,Integer> elementsLevelMap=Maps.newHashMap();
  for (  IndexedInheritableToscaElement element : orderedElements) {
    IndexedInheritableToscaElement parent=element;
    int levelCount=0;
    while (true) {
      if (parent.getDerivedFrom() == null || parent.getDerivedFrom().isEmpty()) {
        break;
      }
      IndexedInheritableToscaElement oldParent=parent;
      parent=elementsByIdMap.get(parent.getDerivedFrom().get(0));
      if (parent == null) {
        break;
      }
      if (oldParent.equals(parent)) {
        throw new IndexingServiceException(parent.getElementId() + "String_Node_Str");
      }
      levelCount++;
    }
    elementsLevelMap.put(element.getElementId(),levelCount);
  }
  Collections.sort(orderedElements,(left,right) -> elementsLevelMap.get(left.getElementId()).compareTo(elementsLevelMap.get(right.getElementId())));
  return orderedElements;
}