Program: 69247
Project: 69247
Buggy source:
protected SplitResult _split(int height,boolean force) throws BirtException {
  if (children.size() == 0) {
    if (isPageBreakBeforeAvoid() && !force) {
      updateChildrenPosition();
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
 else {
      updateChildrenPosition();
      return SplitResult.SUCCEED_WITH_NULL;
    }
  }
  BlockContainerArea newContainer=null;
  int status=SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL;
  int cheight=getContentHeight(height);
  ListIterator iter=children.listIterator();
  int contentHeight=0;
  ArrayList result=new ArrayList();
  ContainerArea current=null;
  ContainerArea previous=null;
  while (iter.hasNext()) {
    previous=current;
    current=(ContainerArea)iter.next();
    int ah=current.getAllocatedHeight();
    contentHeight+=ah;
    if (contentHeight <= cheight && current.finished) {
      result.add(current);
      continue;
    }
 else {
      contentHeight-=ah;
      int childSplitHeight=cheight - contentHeight;
      SplitResult splitResult=current.split(childSplitHeight,force && !isValidResult(result));
      if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
        ContainerArea splitChildArea=splitResult.getResult();
        result.add(splitChildArea);
        status=SplitResult.SPLIT_SUCCEED_WITH_PART;
        contentHeight+=splitChildArea.getAllocatedHeight();
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
        if (force) {
          if (result.size() > 0) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
          }
        }
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) {
        if (isValidResult(result)) {
          if (force) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
 else {
            if (previous.isPageBreakAfterAvoid()) {
              status=SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL;
              break;
            }
 else {
              status=SplitResult.SPLIT_SUCCEED_WITH_PART;
              break;
            }
          }
        }
 else {
          if (force) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
 else {
            if (isPageBreakBeforeAvoid()) {
              return SplitResult.BEFORE_AVOID_WITH_NULL;
            }
 else {
              return SplitResult.SUCCEED_WITH_NULL;
            }
          }
        }
      }
    }
  }
  if (result.size() == children.size()) {
    status=SplitResult.SPLIT_SUCCEED_WITH_PART;
  }
  if (!force && status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
    if (result.size() == 0) {
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
    iter.previous();
    while (iter.hasPrevious()) {
      current=(ContainerArea)iter.previous();
      int ah=current.getAllocatedHeight();
      SplitResult splitResult=current.splitLines(1);
      if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
        result.remove(current);
        contentHeight-=ah;
        continue;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
        result.remove(current);
        ContainerArea splitChildArea=splitResult.getResult();
        contentHeight=contentHeight - ah + splitChildArea.getAllocatedHeight();
        result.add(splitChildArea);
        status=SplitResult.SPLIT_SUCCEED_WITH_PART;
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) {
        result.remove(current);
        int preIndex=iter.previousIndex();
        if (preIndex >= 0) {
          ContainerArea prev=(ContainerArea)children.get(preIndex);
          if (prev.isPageBreakAfterAvoid()) {
            continue;
          }
 else {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
        }
 else {
          if (isPageBreakBeforeAvoid()) {
            return SplitResult.BEFORE_AVOID_WITH_NULL;
          }
 else {
            return SplitResult.SUCCEED_WITH_NULL;
          }
        }
      }
    }
    if (result.size() == 0) {
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
  }
  if (status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
    newContainer=cloneArea();
    for (int i=0; i < result.size(); i++) {
      ContainerArea child=(ContainerArea)result.get(i);
      child.setParent(newContainer);
      newContainer.addChild(child);
      children.remove(child);
    }
    newContainer.updateContentHeight(contentHeight);
  }
  if (newContainer != null) {
    addRepeatedItem();
    updateChildrenPosition();
  }
  return new SplitResult(newContainer,status);
}

Fixed version (ground truth):
protected SplitResult _split(int height,boolean force) throws BirtException {
  if (children.size() == 0) {
    if (isPageBreakBeforeAvoid() && !force) {
      updateChildrenPosition();
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
 else {
      updateChildrenPosition();
      return SplitResult.SUCCEED_WITH_NULL;
    }
  }
  BlockContainerArea newContainer=null;
  int status=SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL;
  int cheight=getContentHeight(height);
  ListIterator iter=children.listIterator();
  int contentHeight=0;
  ArrayList result=new ArrayList();
  ContainerArea current=null;
  ContainerArea previous=null;
  while (iter.hasNext()) {
    previous=current;
    current=(ContainerArea)iter.next();
    int ah=current.getAllocatedHeight();
    contentHeight+=ah;
    if (contentHeight <= cheight && current.finished) {
      result.add(current);
      continue;
    }
 else {
      contentHeight-=ah;
      int childSplitHeight=cheight - contentHeight;
      SplitResult splitResult=current.split(childSplitHeight,force && !isValidResult(result));
      if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
        ContainerArea splitChildArea=splitResult.getResult();
        result.add(splitChildArea);
        status=SplitResult.SPLIT_SUCCEED_WITH_PART;
        contentHeight+=splitChildArea.getAllocatedHeight();
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
        if (force) {
          if (result.size() > 0) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
          }
        }
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) {
        if (isValidResult(result)) {
          if (force) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
 else {
            if (previous.isPageBreakAfterAvoid()) {
              status=SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL;
              break;
            }
 else {
              status=SplitResult.SPLIT_SUCCEED_WITH_PART;
              break;
            }
          }
        }
 else {
          if (force) {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
 else {
            if (isPageBreakBeforeAvoid()) {
              return SplitResult.BEFORE_AVOID_WITH_NULL;
            }
 else {
              return SplitResult.SUCCEED_WITH_NULL;
            }
          }
        }
      }
    }
  }
  if (result.size() == children.size()) {
    status=SplitResult.SPLIT_SUCCEED_WITH_PART;
  }
  if (!force && status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
    if (result.size() == 0) {
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
    iter.previous();
    while (iter.hasPrevious()) {
      current=(ContainerArea)iter.previous();
      int ah=current.getAllocatedHeight();
      SplitResult splitResult=current.splitLines(1);
      if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) {
        result.remove(current);
        contentHeight-=ah;
        continue;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
        result.remove(current);
        ContainerArea splitChildArea=splitResult.getResult();
        contentHeight=contentHeight - ah + splitChildArea.getAllocatedHeight();
        result.add(splitChildArea);
        status=SplitResult.SPLIT_SUCCEED_WITH_PART;
        break;
      }
 else       if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) {
        result.remove(current);
        int preIndex=iter.previousIndex();
        if (preIndex >= 0) {
          ContainerArea prev=(ContainerArea)children.get(preIndex);
          if (prev.isPageBreakAfterAvoid()) {
            continue;
          }
 else {
            status=SplitResult.SPLIT_SUCCEED_WITH_PART;
            break;
          }
        }
 else {
          if (isPageBreakBeforeAvoid()) {
            return SplitResult.BEFORE_AVOID_WITH_NULL;
          }
 else {
            return SplitResult.SUCCEED_WITH_NULL;
          }
        }
      }
    }
    if (result.size() == 0) {
      return SplitResult.BEFORE_AVOID_WITH_NULL;
    }
  }
  if (status == SplitResult.SPLIT_SUCCEED_WITH_PART) {
    newContainer=getSplitArea(result,contentHeight);
  }
  if (newContainer != null) {
    addRepeatedItem();
    updateChildrenPosition();
  }
  return new SplitResult(newContainer,status);
}