Program: 57167
Project: 57167
Buggy source:
@Override public void doLayout(List<? extends IGLLayoutElement> children,float w,float h){
  Map<GLPathwayWindow,IGLLayoutElement> windowToElement=new HashMap<>();
  for (  IGLLayoutElement child : children) {
    windowToElement.put((GLPathwayWindow)child.asElement(),child);
  }
  float freeSpaceVertical=h - padding.vert();
  if (!view.wasContextChanged()) {
    columns.clear();
    for (    PathwayMultiFormInfo info : view.pathwayInfos) {
      addColumn((GLPathwayWindow)info.window);
    }
    Collections.sort(columns,new ColumnPriorityComparator());
    Collections.reverse(columns);
    float level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
    List<PathwayMultiFormInfo> level1Infos=getInfosWithLevel(EEmbeddingID.PATHWAY_LEVEL1);
    Set<PathwayMultiFormInfo> undemotableInfos=new HashSet<>();
    while (undemotableInfos.size() < level1Infos.size() && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
      Collections.sort(level1Infos,new WindowDemotabilityComparator(view));
      Collections.reverse(level1Infos);
      for (      PathwayMultiFormInfo info : level1Infos) {
        if (demote(info)) {
          level1Infos.remove(info);
          break;
        }
 else {
          undemotableInfos.add(info);
        }
      }
    }
    level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
    List<PathwayColumn> level2Columns=getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
    while (level2Columns.size() >= 2 && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
      Collections.sort(level2Columns,new ColumnPriorityComparator());
      Collections.reverse(level2Columns);
      boolean columnRemoved=false;
      while (!columnRemoved) {
        for (        PathwayColumn column : level2Columns) {
          int currentColumnIndex=level2Columns.indexOf(column);
          PathwayColumn firstColumn=level2Columns.get(0);
          if (currentColumnIndex == level2Columns.size() - 1) {
            if (firstColumn != column && firstColumn.windows.isEmpty()) {
              level2Columns.remove(firstColumn);
              columns.remove(firstColumn);
              columnRemoved=true;
              break;
            }
          }
 else {
            PathwayColumn nextColumn=level2Columns.get(currentColumnIndex + 1);
            if (nextColumn.windows.size() < column.windows.size() || column == firstColumn) {
              nextColumn.windows.add(0,column.windows.get(column.windows.size() - 1));
              column.windows.remove(column.windows.size() - 1);
            }
 else             if (firstColumn.windows.isEmpty()) {
              level2Columns.remove(firstColumn);
              columns.remove(firstColumn);
              columnRemoved=true;
              break;
            }
          }
        }
      }
    }
    level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
  }
  List<PathwayMultiFormInfo> level2Infos=getInfosWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
  Set<PathwayMultiFormInfo> undemotableInfos=new HashSet<>();
  List<LayoutSnapshot> snapshots=new ArrayList<>();
  snapshots.add(new LayoutSnapshot());
  while (undemotableInfos.size() < level2Infos.size() && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
    Collections.sort(level2Infos,new WindowDemotabilityComparator(view));
    Collections.reverse(level2Infos);
    for (    PathwayMultiFormInfo info : level2Infos) {
      if (demote(info)) {
        snapshots.add(new LayoutSnapshot());
        break;
      }
 else {
        undemotableInfos.add(info);
      }
    }
  }
  Collections.reverse(snapshots);
  LayoutSnapshot previousSnapshot=null;
  for (int i=0; i < snapshots.size(); i++) {
    LayoutSnapshot snapshot=snapshots.get(i);
    if (previousSnapshot != null) {
      if (previousSnapshot.minTotalWidth < snapshot.minTotalWidth) {
        previousSnapshot.apply();
        break;
      }
 else       if (Float.compare(previousSnapshot.minTotalWidth,snapshot.minTotalWidth) == 0) {
        snapshot.apply();
      }
    }
    previousSnapshot=snapshot;
  }
  if (!view.wasContextChanged()) {
    float level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
  }
  List<PathwayColumn> level2Columns=getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
  squeezeColumns(level2Columns,freeSpaceVertical);
  Set<PathwayMultiFormInfo> unpromotableInfos=new HashSet<>(level2Infos.size());
  while (unpromotableInfos.size() < level2Infos.size()) {
    Collections.sort(level2Infos,new WindowDemotabilityComparator(view));
    for (    PathwayMultiFormInfo info : level2Infos) {
      LayoutSnapshot snapshotPriorPromotion=new LayoutSnapshot();
      if (info.getCurrentEmbeddingID() != EEmbeddingID.PATHWAY_LEVEL2 && promote(info,freeSpaceVertical)) {
        LayoutSnapshot snapshotAfterPromotion=new LayoutSnapshot();
        if ((snapshotAfterPromotion.maxColumnHeight > freeSpaceVertical && snapshotAfterPromotion.maxColumnHeight > snapshotPriorPromotion.maxColumnHeight) || (snapshotAfterPromotion.minTotalWidth > getFreeHorizontalSpace(w) && snapshotAfterPromotion.minTotalWidth > snapshotPriorPromotion.minTotalWidth)) {
          snapshotPriorPromotion.apply();
          unpromotableInfos.add(info);
        }
      }
 else {
        unpromotableInfos.add(info);
      }
    }
  }
  Set<PathwayColumn> level1Columns=new HashSet<>();
  int minTotalLevel1Size=0;
  int totalFixedSize=0;
  List<PathwayColumn> copyColumns=new ArrayList<>(columns);
  Collections.sort(copyColumns,new ColumnPriorityComparator());
  Collections.reverse(copyColumns);
  for (  PathwayColumn column : copyColumns) {
    if (column.getLevelScore() == EEmbeddingID.PATHWAY_LEVEL1.renderPriority()) {
      level1Columns.add(column);
      minTotalLevel1Size+=column.getMinWidth();
    }
 else {
      totalFixedSize+=column.getMinWidth();
    }
  }
  float currentPositionX=padding.left;
  for (  PathwayColumn column : copyColumns) {
    float columnWidth=0;
    if (minTotalLevel1Size == 0) {
      columnWidth=((float)column.getMinWidth() / (float)totalFixedSize) * getFreeHorizontalSpace(w);
    }
 else {
      if (level1Columns.contains(column)) {
        columnWidth=((float)column.getMinWidth() / (float)minTotalLevel1Size) * (getFreeHorizontalSpace(w) - totalFixedSize);
      }
 else {
        columnWidth=column.getMinWidth();
      }
    }
    column.layout(windowToElement,currentPositionX,padding.top,columnWidth,freeSpaceVertical);
    currentPositionX+=columnWidth + gap;
  }
  this.view.setLayoutDirty();
}

Fixed version (ground truth):
@Override public void doLayout(List<? extends IGLLayoutElement> children,float w,float h){
  Map<GLPathwayWindow,IGLLayoutElement> windowToElement=new HashMap<>();
  for (  IGLLayoutElement child : children) {
    windowToElement.put((GLPathwayWindow)child.asElement(),child);
  }
  float freeSpaceVertical=h - padding.vert();
  if (!view.wasContextChanged()) {
    columns.clear();
    for (    PathwayMultiFormInfo info : view.pathwayInfos) {
      addColumn((GLPathwayWindow)info.window);
    }
    Collections.sort(columns,new ColumnPriorityComparator());
    Collections.reverse(columns);
    float level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
    List<PathwayMultiFormInfo> level1Infos=getInfosWithLevel(EEmbeddingID.PATHWAY_LEVEL1);
    Set<PathwayMultiFormInfo> undemotableInfos=new HashSet<>();
    while (undemotableInfos.size() < level1Infos.size() && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
      Collections.sort(level1Infos,new WindowDemotabilityComparator(view));
      Collections.reverse(level1Infos);
      for (      PathwayMultiFormInfo info : level1Infos) {
        if (demote(info)) {
          level1Infos.remove(info);
          break;
        }
 else {
          undemotableInfos.add(info);
        }
      }
    }
    level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
    List<PathwayColumn> level2Columns=getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
    while (level2Columns.size() >= 2 && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
      Collections.sort(level2Columns,new ColumnPriorityComparator());
      Collections.reverse(level2Columns);
      boolean columnRemoved=false;
      while (!columnRemoved) {
        for (        PathwayColumn column : level2Columns) {
          int currentColumnIndex=level2Columns.indexOf(column);
          PathwayColumn firstColumn=level2Columns.get(0);
          if (currentColumnIndex == level2Columns.size() - 1) {
            if (firstColumn != column && firstColumn.windows.isEmpty()) {
              level2Columns.remove(firstColumn);
              columns.remove(firstColumn);
              columnRemoved=true;
              break;
            }
          }
 else {
            PathwayColumn nextColumn=level2Columns.get(currentColumnIndex + 1);
            if (nextColumn.windows.size() < column.windows.size() || column == firstColumn) {
              nextColumn.windows.add(0,column.windows.get(column.windows.size() - 1));
              column.windows.remove(column.windows.size() - 1);
            }
 else             if (firstColumn.windows.isEmpty()) {
              level2Columns.remove(firstColumn);
              columns.remove(firstColumn);
              columnRemoved=true;
              break;
            }
          }
        }
      }
    }
    level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
  }
  List<PathwayMultiFormInfo> level2Infos=getInfosWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
  Set<PathwayMultiFormInfo> undemotableInfos=new HashSet<>();
  List<LayoutSnapshot> snapshots=new ArrayList<>();
  snapshots.add(new LayoutSnapshot());
  while (undemotableInfos.size() < level2Infos.size() && !isSufficientHorizontalSpace(getFreeHorizontalSpace(w))) {
    Collections.sort(level2Infos,new WindowDemotabilityComparator(view));
    Collections.reverse(level2Infos);
    for (    PathwayMultiFormInfo info : level2Infos) {
      if (demote(info)) {
        snapshots.add(new LayoutSnapshot());
        break;
      }
 else {
        undemotableInfos.add(info);
      }
    }
  }
  Collections.reverse(snapshots);
  LayoutSnapshot previousSnapshot=null;
  for (int i=0; i < snapshots.size(); i++) {
    LayoutSnapshot snapshot=snapshots.get(i);
    if (previousSnapshot != null) {
      if (previousSnapshot.minTotalWidth < snapshot.minTotalWidth) {
        previousSnapshot.apply();
        break;
      }
 else       if (Float.compare(previousSnapshot.minTotalWidth,snapshot.minTotalWidth) == 0) {
        snapshot.apply();
      }
    }
    previousSnapshot=snapshot;
  }
  if (!view.wasContextChanged()) {
    float level1FreeSpaceHorizontal=w - padding.hor() - getTotalColumnWidth(getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2));
    optimizeLevel1Space(level1FreeSpaceHorizontal,freeSpaceVertical);
  }
  List<PathwayColumn> level2Columns=getColumnsWithMaxLevel(EEmbeddingID.PATHWAY_LEVEL2);
  squeezeColumns(level2Columns,freeSpaceVertical);
  Set<PathwayMultiFormInfo> unpromotableInfos=new HashSet<>(level2Infos.size());
  while (unpromotableInfos.size() < level2Infos.size()) {
    Collections.sort(level2Infos,new WindowDemotabilityComparator(view));
    for (    PathwayMultiFormInfo info : level2Infos) {
      LayoutSnapshot snapshotPriorPromotion=new LayoutSnapshot();
      if (info.getCurrentEmbeddingID() != EEmbeddingID.PATHWAY_LEVEL2 && promote(info,freeSpaceVertical)) {
        LayoutSnapshot snapshotAfterPromotion=new LayoutSnapshot();
        if ((snapshotAfterPromotion.maxL2ColumnHeight > freeSpaceVertical && snapshotAfterPromotion.maxL2ColumnHeight > snapshotPriorPromotion.maxL2ColumnHeight) || (snapshotAfterPromotion.minTotalWidth > getFreeHorizontalSpace(w) && snapshotAfterPromotion.minTotalWidth > snapshotPriorPromotion.minTotalWidth)) {
          snapshotPriorPromotion.apply();
          unpromotableInfos.add(info);
        }
      }
 else {
        unpromotableInfos.add(info);
      }
    }
  }
  Set<PathwayColumn> level1Columns=new HashSet<>();
  int minTotalLevel1Size=0;
  int totalFixedSize=0;
  List<PathwayColumn> copyColumns=new ArrayList<>(columns);
  Collections.sort(copyColumns,new ColumnPriorityComparator());
  Collections.reverse(copyColumns);
  for (  PathwayColumn column : copyColumns) {
    if (column.getLevelScore() == EEmbeddingID.PATHWAY_LEVEL1.renderPriority()) {
      level1Columns.add(column);
      minTotalLevel1Size+=column.getMinWidth();
    }
 else {
      totalFixedSize+=column.getMinWidth();
    }
  }
  float currentPositionX=padding.left;
  for (  PathwayColumn column : copyColumns) {
    float columnWidth=0;
    if (minTotalLevel1Size == 0) {
      columnWidth=((float)column.getMinWidth() / (float)totalFixedSize) * getFreeHorizontalSpace(w);
    }
 else {
      if (level1Columns.contains(column)) {
        columnWidth=((float)column.getMinWidth() / (float)minTotalLevel1Size) * (getFreeHorizontalSpace(w) - totalFixedSize);
      }
 else {
        columnWidth=column.getMinWidth();
      }
    }
    column.layout(windowToElement,currentPositionX,padding.top,columnWidth,freeSpaceVertical);
    currentPositionX+=columnWidth + gap;
  }
  this.view.setLayoutDirty();
  view.setWasContextChanged(false);
}