Program: 76658
Project: 76658
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();
        PDFTextLM.this.newLine();
        vestigeIndex=-1;
        return;
      }
      currentPos=0;
      this.wr=new DefaultWordRecognizer(chunk.getText());
    }
 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) {
      Dimension d=new Dimension(0,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      IArea builtArea=buildArea("String_Node_Str",content,chunk.getFontInfo(),d);
      PDFTextLM.this.addTextLine(builtArea);
      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=new DefaultHyphenationManager();
    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();
        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) {
        FontHandler handler=new FontHandler(content);
        handler.selectFont(MaxHighChar);
        ContainerArea con=(ContainerArea)createInlineContainer(content,false,true);
        con.setWidth(0);
        con.setHeight((int)(handler.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO) + topBorder + topPadding+ bottomBorder+ bottomPadding);
        PDFTextLM.this.addSpaceHolder(con);
        currentPos=chunk.getText().length();
        PDFTextLM.this.newLine();
        vestigeIndex=-1;
        return;
      }
      currentPos=0;
      this.wr=new DefaultWordRecognizer(chunk.getText());
    }
 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) {
      Dimension d=new Dimension(0,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      IArea builtArea=buildArea("String_Node_Str",content,chunk.getFontInfo(),d);
      PDFTextLM.this.addTextLine(builtArea);
      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=new DefaultHyphenationManager();
    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();
        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;
  }
}