Program: 75180
Project: 75180
Buggy source:
private void handleNext(){
  int freeSpace=PDFTextLM.this.getFreeSpace();
  if (isNew || currentPos == chunk.getText().length()) {
    if (cg.hasMore()) {
      chunk=cg.getNext();
      if (chunk == Chunk.HARD_LINE_BREAK) {
        currentPos=chunk.getText().length();
        AbstractArea con=(AbstractArea)createInlineContainer(content,false,false);
        con.setWidth(0);
        if (null == chunk.getFontInfo()) {
          IStyle style=content.getComputedStyle();
          con.setHeight(getDimensionValue(style.getProperty(StyleConstants.STYLE_FONT_SIZE)) + topBorder + topPadding+ bottomBorder+ bottomPadding);
        }
 else {
          con.setHeight((int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO) + topBorder + topPadding+ bottomBorder+ bottomPadding);
        }
        PDFTextLM.this.addSpaceHolder(con);
        PDFTextLM.this.newLine();
        vestigeIndex=-1;
        return;
      }
      currentPos=0;
      vestigeIndex=-1;
      vestigeLength=0;
      wr=new ICUWordRecognizer(chunk.getText(),context.getLocale());
    }
 else {
      return;
    }
  }
  if (isNew) {
    isNew=false;
    if (isInline) {
      AbstractArea con=(AbstractArea)createInlineContainer(content,true,false);
      con.setWidth(leftBorder + leftPadding);
      con.setHeight((int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO) + topBorder + topPadding+ bottomBorder+ bottomPadding);
      PDFTextLM.this.addSpaceHolder(con);
      leftSpaceHolder=leftMargin + leftBorder + leftPadding;
      freeSpace-=leftSpaceHolder;
    }
  }
  String str=null;
  Word currentWord=null;
  if (-1 == vestigeIndex) {
    currentWord=wr.getNextWord();
    if (null == currentWord) {
      return;
    }
    str=currentWord.getValue();
    areaStartPos=chunk.getOffset() + currentWord.getStart();
  }
 else {
    str=chunk.getText().substring(vestigeIndex,vestigeIndex + vestigeLength);
    areaStartPos=chunk.getOffset() + vestigeIndex;
  }
  int prevAreaWidth=0;
  int areaWidth=(int)(chunk.getFontInfo().getWordWidth(chunk.getText().substring(currentPos,currentPos + str.length())) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing;
  if (isInline) {
    if (isAtLast(chunk.getOffset() + currentPos + str.length())) {
      rightSpaceHolder=rightMargin + rightBorder + rightPadding;
      freeSpace-=rightSpaceHolder;
    }
  }
  while (freeSpace >= areaWidth) {
    currentPos+=str.length();
    currentWord=wr.getNextWord();
    if (null == currentWord) {
      str=null;
      break;
    }
    str=currentWord.getValue();
    prevAreaWidth=areaWidth;
    areaWidth+=(int)(chunk.getFontInfo().getWordWidth(chunk.getText().substring(currentPos,currentPos + str.length())) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing;
    if (isAtLast(chunk.getOffset() + currentPos + str.length())) {
      rightSpaceHolder=rightMargin + rightBorder + rightPadding;
      freeSpace-=rightSpaceHolder;
    }
  }
  int length=chunk.getText().length();
  if (currentPos == length) {
    Dimension d=new Dimension(areaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),chunk.getText().length());
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    vestigeIndex=-1;
    vestigeLength=0;
    return;
  }
  if (maxLineSpace < chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO + letterSpacing * str.length() + wordSpacing) {
    if (0 == str.length()) {
      vestigeIndex=-1;
      vestigeLength=0;
      return;
    }
    IHyphenationManager hm;
    if (ENABLE_HYPHENATION) {
      hm=new DefaultHyphenationManager();
    }
 else {
      hm=new DummyHyphenationManager();
    }
    Hyphenation hyph=hm.getHyphenation(str);
    int endHyphenIndex=hyphen(0,freeSpace - prevAreaWidth,hyph,chunk.getFontInfo());
    if (endHyphenIndex == 0) {
      if (nothingSplitted) {
        str=hyph.getHyphenText(0,endHyphenIndex + 1);
        addByForce=true;
        nothingSplitted=false;
      }
 else {
        nothingSplitted=true;
        vestigeIndex=currentPos;
        vestigeLength=(null == currentWord) ? vestigeLength : currentWord.getLength();
        Dimension d=new Dimension(prevAreaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),currentPos);
        IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
        PDFTextLM.this.addTextLine(builtArea);
        PDFTextLM.this.newLine();
        return;
      }
    }
 else {
      str=hyph.getHyphenText(0,endHyphenIndex);
    }
    currentPos+=str.length();
    vestigeIndex=currentPos;
    vestigeLength=(null == currentWord) ? vestigeLength - str.length() : currentWord.getLength() - str.length();
    Dimension d=null;
    if (addByForce) {
      d=new Dimension(freeSpace,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      addByForce=false;
    }
 else {
      d=new Dimension(prevAreaWidth + (int)(chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length(),(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    }
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),vestigeIndex);
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    return;
  }
 else {
    Dimension d=new Dimension(prevAreaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),currentPos);
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    vestigeIndex=(null == currentWord) ? -1 : currentWord.getStart();
    vestigeLength=(null == currentWord) ? 0 : currentWord.getLength();
    return;
  }
}

Fixed version (ground truth):
private void handleNext(){
  int freeSpace=PDFTextLM.this.getFreeSpace();
  if (isNew || currentPos == chunk.getText().length()) {
    if (cg.hasMore()) {
      chunk=cg.getNext();
      if (chunk == Chunk.HARD_LINE_BREAK) {
        currentPos=chunk.getText().length();
        AbstractArea con=(AbstractArea)createInlineContainer(content,false,false);
        con.setWidth(0);
        if (null == chunk.getFontInfo()) {
          IStyle style=content.getComputedStyle();
          con.setHeight(getDimensionValue(style.getProperty(StyleConstants.STYLE_FONT_SIZE)) + topBorder + topPadding+ bottomBorder+ bottomPadding);
        }
 else {
          con.setHeight((int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO) + topBorder + topPadding+ bottomBorder+ bottomPadding);
        }
        PDFTextLM.this.addSpaceHolder(con);
        PDFTextLM.this.newLine();
        vestigeIndex=-1;
        return;
      }
      currentPos=0;
      vestigeIndex=-1;
      vestigeLength=0;
      wr=new ICUWordRecognizer(chunk.getText(),context.getLocale());
    }
 else {
      return;
    }
  }
  if (isNew) {
    isNew=false;
    if (isInline) {
      AbstractArea con=(AbstractArea)createInlineContainer(content,true,false);
      con.setWidth(leftBorder + leftPadding);
      con.setHeight((int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO) + topBorder + topPadding+ bottomBorder+ bottomPadding);
      PDFTextLM.this.addSpaceHolder(con);
      leftSpaceHolder=leftMargin + leftBorder + leftPadding;
      freeSpace-=leftSpaceHolder;
    }
  }
  String str=null;
  Word currentWord=null;
  if (-1 == vestigeIndex) {
    currentWord=wr.getNextWord();
    if (null == currentWord) {
      return;
    }
    str=currentWord.getValue();
    areaStartPos=chunk.getOffset() + currentWord.getStart();
  }
 else {
    str=chunk.getText().substring(vestigeIndex,vestigeIndex + vestigeLength);
    areaStartPos=chunk.getOffset() + vestigeIndex;
  }
  int prevAreaWidth=0;
  int areaWidth=(int)(chunk.getFontInfo().getWordWidth(chunk.getText().substring(currentPos,currentPos + str.length())) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing;
  if (isInline) {
    if (isAtLast(chunk.getOffset() + currentPos + str.length())) {
      rightSpaceHolder=rightMargin + rightBorder + rightPadding;
      freeSpace-=rightSpaceHolder;
    }
  }
  while (freeSpace >= areaWidth) {
    currentPos+=str.length();
    currentWord=wr.getNextWord();
    if (null == currentWord) {
      str=null;
      break;
    }
    str=currentWord.getValue();
    prevAreaWidth=areaWidth;
    areaWidth+=(int)(chunk.getFontInfo().getWordWidth(chunk.getText().substring(currentPos,currentPos + str.length())) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing;
    if (isAtLast(chunk.getOffset() + currentPos + str.length())) {
      rightSpaceHolder=rightMargin + rightBorder + rightPadding;
      freeSpace-=rightSpaceHolder;
    }
  }
  int length=chunk.getText().length();
  if (currentPos == length) {
    Dimension d=new Dimension(areaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),chunk.getText().length());
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    vestigeIndex=-1;
    vestigeLength=0;
    return;
  }
  if (maxLineSpace < chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO + letterSpacing * str.length() + wordSpacing) {
    if (0 == str.length()) {
      vestigeIndex=-1;
      vestigeLength=0;
      return;
    }
    IHyphenationManager hm;
    if (ENABLE_HYPHENATION) {
      hm=new DefaultHyphenationManager();
    }
 else {
      hm=new DummyHyphenationManager();
    }
    Hyphenation hyph=hm.getHyphenation(str);
    int endHyphenIndex=hyphen(0,freeSpace - prevAreaWidth,hyph,chunk.getFontInfo());
    if (endHyphenIndex == 0) {
      if (nothingSplitted) {
        str=hyph.getHyphenText(0,endHyphenIndex + 1);
        addByForce=true;
        nothingSplitted=false;
      }
 else {
        nothingSplitted=true;
        vestigeIndex=currentPos;
        vestigeLength=(null == currentWord) ? vestigeLength : currentWord.getLength();
        if (0 == prevAreaWidth)         return;
        Dimension d=new Dimension(prevAreaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),currentPos);
        IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
        PDFTextLM.this.addTextLine(builtArea);
        PDFTextLM.this.newLine();
        return;
      }
    }
 else {
      str=hyph.getHyphenText(0,endHyphenIndex);
    }
    currentPos+=str.length();
    vestigeIndex=currentPos;
    vestigeLength=(null == currentWord) ? vestigeLength - str.length() : currentWord.getLength() - str.length();
    Dimension d=null;
    if (addByForce) {
      d=new Dimension(freeSpace,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      addByForce=false;
    }
 else {
      d=new Dimension(prevAreaWidth + (int)(chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length(),(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    }
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),vestigeIndex);
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    return;
  }
 else {
    Dimension d=new Dimension(prevAreaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=chunk.getText().substring(areaStartPos - chunk.getOffset(),currentPos);
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    vestigeIndex=(null == currentWord) ? -1 : currentWord.getStart();
    vestigeLength=(null == currentWord) ? 0 : currentWord.getLength();
    return;
  }
}