Program: 37218
Project: 37218
Buggy source:
/** 
 * Suppose a piece of documentation has a relative link.  When you copy that documetation to another place such as the index or class-use page, that relative link will no longer work.  We should redirect those links so that they will work again. <p> Here is the algorithm used to fix the link: <p> &lt;relative link&gt; => docRoot + &lt;relative path to file&gt; + &lt;relative link&gt; <p> For example, suppose com.sun.javadoc.RootDoc has this link: &lt;a href="package-summary.html"&gt;The package Page&lt;/a&gt; <p> If this link appeared in the index, we would redirect the link like this: &lt;a href="./com/sun/javadoc/package-summary.html"&gt;The package Page&lt;/a&gt;
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc,String text){
  if (doc == null || shouldNotRedirectRelativeLinks()) {
    return text;
  }
  String redirectPathFromRoot;
  if (doc instanceof ClassDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath(((ClassDoc)doc).containingPackage());
  }
 else   if (doc instanceof MemberDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath(((MemberDoc)doc).containingPackage());
  }
 else   if (doc instanceof PackageDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath((PackageDoc)doc);
  }
 else {
    return text;
  }
  if (!redirectPathFromRoot.endsWith(DirectoryManager.URL_FILE_SEPARATOR)) {
    redirectPathFromRoot+=DirectoryManager.URL_FILE_SEPARATOR;
  }
  int end, begin=text.toLowerCase().indexOf("String_Node_Str");
  if (begin >= 0) {
    StringBuffer textBuff=new StringBuffer(text);
    while (begin >= 0) {
      if (textBuff.length() > begin + 2 && !Character.isWhitespace(textBuff.charAt(begin + 2))) {
        begin=textBuff.toString().toLowerCase().indexOf("String_Node_Str",begin + 1);
        continue;
      }
      begin=textBuff.indexOf("String_Node_Str",begin) + 1;
      end=textBuff.indexOf("String_Node_Str",begin + 1);
      if (begin == 0) {
        configuration.root.printWarning(doc.position(),configuration.getText("String_Node_Str",text));
        break;
      }
      if (end == -1) {
        break;
      }
      if (textBuff.substring(begin,end).indexOf("String_Node_Str") != -1) {
        begin=textBuff.indexOf("String_Node_Str",begin) + 1;
        end=textBuff.indexOf("String_Node_Str",begin + 1);
        if (begin == 0 || end == -1) {
          break;
        }
      }
      String relativeLink=textBuff.substring(begin,end);
      if (!(relativeLink.toLowerCase().startsWith("String_Node_Str") || relativeLink.toLowerCase().startsWith("String_Node_Str") || relativeLink.toLowerCase().startsWith("String_Node_Str")|| relativeLink.toLowerCase().startsWith("String_Node_Str"))) {
        relativeLink="String_Node_Str" + (new DocRootTaglet()).getName() + "String_Node_Str"+ redirectPathFromRoot+ relativeLink;
        textBuff.replace(begin,end,relativeLink);
      }
      begin=textBuff.toString().toLowerCase().indexOf("String_Node_Str",begin + 1);
    }
    return textBuff.toString();
  }
  return text;
}

Fixed version (ground truth):
/** 
 * Suppose a piece of documentation has a relative link.  When you copy that documetation to another place such as the index or class-use page, that relative link will no longer work.  We should redirect those links so that they will work again. <p> Here is the algorithm used to fix the link: <p>  {@literal <relative link> => docRoot + <relative path to file> + <relative link> }<p> For example, suppose com.sun.javadoc.RootDoc has this link:  {@literal <a href="package-summary.html">The package Page</a> }<p> If this link appeared in the index, we would redirect the link like this:  {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc,String text){
  if (doc == null || shouldNotRedirectRelativeLinks()) {
    return text;
  }
  String redirectPathFromRoot;
  if (doc instanceof ClassDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath(((ClassDoc)doc).containingPackage());
  }
 else   if (doc instanceof MemberDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath(((MemberDoc)doc).containingPackage());
  }
 else   if (doc instanceof PackageDoc) {
    redirectPathFromRoot=DirectoryManager.getDirectoryPath((PackageDoc)doc);
  }
 else {
    return text;
  }
  if (!redirectPathFromRoot.endsWith(DirectoryManager.URL_FILE_SEPARATOR)) {
    redirectPathFromRoot+=DirectoryManager.URL_FILE_SEPARATOR;
  }
  int end, begin=text.toLowerCase().indexOf("String_Node_Str");
  if (begin >= 0) {
    StringBuffer textBuff=new StringBuffer(text);
    while (begin >= 0) {
      if (textBuff.length() > begin + 2 && !Character.isWhitespace(textBuff.charAt(begin + 2))) {
        begin=textBuff.toString().toLowerCase().indexOf("String_Node_Str",begin + 1);
        continue;
      }
      begin=textBuff.indexOf("String_Node_Str",begin) + 1;
      end=textBuff.indexOf("String_Node_Str",begin + 1);
      if (begin == 0) {
        configuration.root.printWarning(doc.position(),configuration.getText("String_Node_Str",text));
        break;
      }
      if (end == -1) {
        break;
      }
      if (textBuff.substring(begin,end).indexOf("String_Node_Str") != -1) {
        begin=textBuff.indexOf("String_Node_Str",begin) + 1;
        end=textBuff.indexOf("String_Node_Str",begin + 1);
        if (begin == 0 || end == -1) {
          break;
        }
      }
      String relativeLink=textBuff.substring(begin,end);
      if (!(relativeLink.toLowerCase().startsWith("String_Node_Str") || relativeLink.toLowerCase().startsWith("String_Node_Str") || relativeLink.toLowerCase().startsWith("String_Node_Str")|| relativeLink.toLowerCase().startsWith("String_Node_Str"))) {
        relativeLink="String_Node_Str" + (new DocRootTaglet()).getName() + "String_Node_Str"+ redirectPathFromRoot+ relativeLink;
        textBuff.replace(begin,end,relativeLink);
      }
      begin=textBuff.toString().toLowerCase().indexOf("String_Node_Str",begin + 1);
    }
    return textBuff.toString();
  }
  return text;
}