Program: 35841
Project: 35841
Buggy source:
/** 
 * Retrieves a template from the provider application and renders it to the writer replacing the parameters with the given map. If "page" param is null, the whole page will be used as the template.<br /> eg: The template "mytemplate" can be delimited in the provider page by comments "&lt;!--$begintemplate$mytemplate$--&gt;" and "&lt;!--$endtemplate$mytemplate$--&gt;".<br /> Inside the template, the parameters can be defined by comments.<br /> eg: parameter named "myparam" should be delimited by comments "&lt;!--$beginparam$myparam$--&gt;" and "&lt;!--$endparam$myparam$--&gt;"
 * @param page
 * @param name
 * @param writer
 * @param context
 * @param params
 * @param replaceRules the replace rules to be applied on the block
 * @param parameters
 * @throws IOException
 */
public final void renderTemplate(String page,String name,Writer writer,Context context,Map<String,String> params,Map<String,String> replaceRules,Map<String,String> parameters) throws IOException {
  Target target=new Target(page,context,null);
  String content=getResourceAsString(target).toString();
  StringBuilder sb=new StringBuilder();
  if (content != null) {
    if (name != null) {
      String beginString="String_Node_Str" + name + "String_Node_Str";
      String endString="String_Node_Str" + name + "String_Node_Str";
      int begin=content.indexOf(beginString);
      int end=content.indexOf(endString);
      if (begin == -1 || end == -1) {
        log.warn("String_Node_Str" + page + "String_Node_Str"+ name);
      }
 else {
        log.debug("String_Node_Str" + page + "String_Node_Str"+ name);
        sb.append(content,begin + beginString.length(),end);
      }
    }
 else {
      log.debug("String_Node_Str" + page);
      sb.append(content);
    }
    if (params != null) {
      for (      Entry<String,String> param : params.entrySet()) {
        int lastIndexOfString=0;
        String key=param.getKey();
        String value=param.getValue();
        String beginString="String_Node_Str" + key + "String_Node_Str";
        String endString="String_Node_Str" + key + "String_Node_Str";
        while (lastIndexOfString >= 0) {
          int begin=sb.indexOf(beginString,lastIndexOfString);
          int end=sb.indexOf(endString,lastIndexOfString);
          if (!(begin == -1 || end == -1)) {
            sb.replace(begin + beginString.length(),end,value);
          }
          if (begin == -1 || end == -1) {
            lastIndexOfString=-1;
          }
 else {
            lastIndexOfString=begin + beginString.length() + value.length()+ endString.length();
          }
        }
      }
    }
  }
 else {
    if (params != null) {
      for (      Entry<String,String> param : params.entrySet()) {
        sb.append(param.getValue());
      }
    }
  }
  writer.append(StringUtils.replace(sb,replaceRules));
}

Fixed version (ground truth):
/** 
 * Retrieves a template from the provider application and renders it to the writer replacing the parameters with the given map. If "page" param is null, the whole page will be used as the template.<br /> eg: The template "mytemplate" can be delimited in the provider page by comments "&lt;!--$begintemplate$mytemplate$--&gt;" and "&lt;!--$endtemplate$mytemplate$--&gt;".<br /> Inside the template, the parameters can be defined by comments.<br /> eg: parameter named "myparam" should be delimited by comments "&lt;!--$beginparam$myparam$--&gt;" and "&lt;!--$endparam$myparam$--&gt;"
 * @param page Address of the page containing the template
 * @param name Template name
 * @param writer Writer where to write the result
 * @param context User context
 * @param params Blocks to replace inside the template
 * @param replaceRules The replace rules to be applied on the block
 * @param parameters Parameters to be added to the request
 * @throws IOException If an IOException occurs while writing to the writer
 */
public final void renderTemplate(String page,String name,Writer writer,Context context,Map<String,String> params,Map<String,String> replaceRules,Map<String,String> parameters) throws IOException {
  Target target=new Target(page,context,parameters);
  String content=getResourceAsString(target).toString();
  StringBuilder sb=new StringBuilder();
  if (content != null) {
    if (name != null) {
      String beginString="String_Node_Str" + name + "String_Node_Str";
      String endString="String_Node_Str" + name + "String_Node_Str";
      int begin=content.indexOf(beginString);
      int end=content.indexOf(endString);
      if (begin == -1 || end == -1) {
        log.warn("String_Node_Str" + page + "String_Node_Str"+ name);
      }
 else {
        log.debug("String_Node_Str" + page + "String_Node_Str"+ name);
        sb.append(content,begin + beginString.length(),end);
      }
    }
 else {
      log.debug("String_Node_Str" + page);
      sb.append(content);
    }
    if (params != null) {
      for (      Entry<String,String> param : params.entrySet()) {
        int lastIndexOfString=0;
        String key=param.getKey();
        String value=param.getValue();
        String beginString="String_Node_Str" + key + "String_Node_Str";
        String endString="String_Node_Str" + key + "String_Node_Str";
        while (lastIndexOfString >= 0) {
          int begin=sb.indexOf(beginString,lastIndexOfString);
          int end=sb.indexOf(endString,lastIndexOfString);
          if (!(begin == -1 || end == -1)) {
            sb.replace(begin + beginString.length(),end,value);
          }
          if (begin == -1 || end == -1) {
            lastIndexOfString=-1;
          }
 else {
            lastIndexOfString=begin + beginString.length() + value.length()+ endString.length();
          }
        }
      }
    }
  }
 else {
    if (params != null) {
      for (      Entry<String,String> param : params.entrySet()) {
        sb.append(param.getValue());
      }
    }
  }
  writer.append(StringUtils.replace(sb,replaceRules));
}