Program: 73239
Project: 73239
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) {
        FontHandler handler=new FontHandler(context.getFontManager(),content,false);
        Dimension d=new Dimension(0,(int)(handler.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        IArea con=buildArea("String_Node_Str",content,handler.getFontInfo(),d);
        PDFTextLM.this.addSpaceHolder(con);
        PDFTextLM.this.newLine();
        currentPos=chunk.getText().length();
        vestigeIndex=-1;
        return;
      }
      if (!pdfTextWrapping) {
        String originalText=chunk.getText();
        int areaWidth=(int)(chunk.getFontInfo().getWordWidth(originalText) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * originalText.length();
        Dimension d=new Dimension(areaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
        PDFTextLM.this.addTextLine(builtArea);
        PDFTextLM.this.newLine();
        currentPos=chunk.getText().length();
        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)AreaFactory.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;
    }
  }
  if (maxLineSpace < chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO + letterSpacing * str.length() + wordSpacing) {
    if (0 == str.length()) {
      vestigeIndex=-1;
      vestigeLength=0;
      return;
    }
    Dimension d=new Dimension((int)(chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=str;
    if (maxLineSpace != freeSpace) {
      PDFTextLM.this.newLine();
    }
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    currentPos+=str.length();
    vestigeIndex=-1;
    vestigeLength=0;
    return;
  }
  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;
  }
 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();
    if (null == currentWord) {
      if (originalText.length() == 0)       return;
      vestigeIndex=-1;
      vestigeLength=0;
    }
 else {
      vestigeIndex=currentWord.getStart();
      vestigeLength=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(context.getFontManager(),content,false);
        Dimension d=new Dimension(0,(int)(handler.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        IArea con=buildArea("String_Node_Str",content,handler.getFontInfo(),d);
        PDFTextLM.this.addSpaceHolder(con);
        PDFTextLM.this.newLine();
        currentPos=chunk.getText().length();
        vestigeIndex=-1;
        return;
      }
      if (!pdfTextWrapping) {
        String originalText=chunk.getText();
        int areaWidth=(int)(chunk.getFontInfo().getWordWidth(originalText) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * originalText.length();
        Dimension d=new Dimension(areaWidth,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
        IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
        PDFTextLM.this.addTextLine(builtArea);
        PDFTextLM.this.newLine();
        currentPos=chunk.getText().length();
        vestigeIndex=-1;
        return;
      }
      currentPos=0;
      vestigeIndex=-1;
      vestigeLength=0;
      wr=new WordRecognizerWrapper(chunk.getText(),context.getLocale());
    }
 else {
      return;
    }
  }
  if (isNew) {
    isNew=false;
    if (isInline) {
      AbstractArea con=(AbstractArea)AreaFactory.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;
    }
  }
  if (maxLineSpace < chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO + letterSpacing * str.length() + wordSpacing) {
    if (0 == str.length()) {
      vestigeIndex=-1;
      vestigeLength=0;
      return;
    }
    Dimension d=new Dimension((int)(chunk.getFontInfo().getWordWidth(str) * PDFConstants.LAYOUT_TO_PDF_RATIO) + letterSpacing * str.length() + wordSpacing,(int)(chunk.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
    String originalText=str;
    if (maxLineSpace != freeSpace) {
      PDFTextLM.this.newLine();
    }
    IArea builtArea=buildArea(getReverseText(originalText),content,chunk.getFontInfo(),d);
    PDFTextLM.this.addTextLine(builtArea);
    PDFTextLM.this.newLine();
    currentPos+=str.length();
    vestigeIndex=-1;
    vestigeLength=0;
    return;
  }
  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;
  }
 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();
    if (null == currentWord) {
      if (originalText.length() == 0)       return;
      vestigeIndex=-1;
      vestigeLength=0;
    }
 else {
      vestigeIndex=currentWord.getStart();
      vestigeLength=currentWord.getLength();
    }
    return;
  }
}