Program: 15628
Project: 15628
Buggy source:
/** 
 * "visit" a macro.
 */
void visit(Macro macro,Map namedArgs,List positionalArgs,List bodyParameterNames,TemplateElement nestedBlock) throws TemplateException, IOException {
  if (macro == Macro.DO_NOTHING_MACRO) {
    return;
  }
  pushElement(macro);
  try {
    Macro.Context previousMacroContext=currentMacroContext;
    Macro.Context mc=macro.new Context(this,nestedBlock,bodyParameterNames);
    String catchAll=macro.getCatchAll();
    TemplateModel unknownVars=null;
    if (namedArgs != null) {
      if (catchAll != null)       unknownVars=new SimpleHash();
      for (Iterator it=namedArgs.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry=(Map.Entry)it.next();
        String varName=(String)entry.getKey();
        boolean hasVar=macro.hasArgNamed(varName);
        if (hasVar || catchAll != null) {
          Expression arg=(Expression)entry.getValue();
          TemplateModel value=arg.eval(this);
          if (hasVar) {
            mc.setLocalVar(varName,value);
          }
 else {
            ((SimpleHash)unknownVars).put(varName,value);
          }
        }
 else {
          throw new _MiscTemplateException(this,new Object[]{"String_Node_Str",new _DelayedJQuote(macro.getName()),"String_Node_Str",varName});
        }
      }
    }
 else     if (positionalArgs != null) {
      if (catchAll != null)       unknownVars=new SimpleSequence();
      String[] argumentNames=macro.getArgumentNamesInternal();
      int size=positionalArgs.size();
      if (argumentNames.length < size && catchAll == null) {
        throw new _MiscTemplateException(this,new Object[]{"String_Node_Str" + StringUtil.jQuote(macro.getName()) + "String_Node_Str"+ argumentNames.length+ "String_Node_Str"});
      }
      for (int i=0; i < size; i++) {
        Expression argExp=(Expression)positionalArgs.get(i);
        TemplateModel argModel=argExp.eval(this);
        try {
          if (i < argumentNames.length) {
            String argName=argumentNames[i];
            mc.setLocalVar(argName,argModel);
          }
 else {
            ((SimpleSequence)unknownVars).add(argModel);
          }
        }
 catch (        RuntimeException re) {
          throw new _MiscTemplateException(re,this);
        }
      }
    }
    if (catchAll != null) {
      mc.setLocalVar(catchAll,unknownVars);
    }
    ArrayList prevLocalContextStack=localContextStack;
    localContextStack=null;
    Namespace prevNamespace=currentNamespace;
    Configurable prevParent=getParent();
    currentNamespace=(Namespace)macroToNamespaceLookup.get(macro);
    currentMacroContext=mc;
    try {
      mc.runMacro(this);
    }
 catch (    ReturnInstruction.Return re) {
    }
catch (    TemplateException te) {
      handleTemplateException(te);
    }
 finally {
      currentMacroContext=previousMacroContext;
      localContextStack=prevLocalContextStack;
      currentNamespace=prevNamespace;
      setParent(prevParent);
    }
  }
  finally {
    popElement();
  }
}

Fixed version (ground truth):
/** 
 * "visit" a macro.
 */
void visit(Macro macro,Map namedArgs,List positionalArgs,List bodyParameterNames,TemplateElement nestedBlock) throws TemplateException, IOException {
  if (macro == Macro.DO_NOTHING_MACRO) {
    return;
  }
  pushElement(macro);
  try {
    Macro.Context previousMacroContext=currentMacroContext;
    Macro.Context mc=macro.new Context(this,nestedBlock,bodyParameterNames);
    String catchAll=macro.getCatchAll();
    TemplateModel unknownVars=null;
    if (namedArgs != null) {
      if (catchAll != null)       unknownVars=new SimpleHash();
      for (Iterator it=namedArgs.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry=(Map.Entry)it.next();
        String varName=(String)entry.getKey();
        boolean hasVar=macro.hasArgNamed(varName);
        if (hasVar || catchAll != null) {
          Expression arg=(Expression)entry.getValue();
          TemplateModel value=arg.eval(this);
          if (hasVar) {
            mc.setLocalVar(varName,value);
          }
 else {
            ((SimpleHash)unknownVars).put(varName,value);
          }
        }
 else {
          throw new _MiscTemplateException(this,new Object[]{"String_Node_Str",new _DelayedJQuote(macro.getName()),"String_Node_Str",varName});
        }
      }
    }
 else     if (positionalArgs != null) {
      if (catchAll != null)       unknownVars=new SimpleSequence();
      String[] argumentNames=macro.getArgumentNamesInternal();
      int size=positionalArgs.size();
      if (argumentNames.length < size && catchAll == null) {
        throw new _MiscTemplateException(this,new Object[]{"String_Node_Str" + StringUtil.jQuote(macro.getName()) + "String_Node_Str"+ argumentNames.length+ "String_Node_Str"});
      }
      for (int i=0; i < size; i++) {
        Expression argExp=(Expression)positionalArgs.get(i);
        TemplateModel argModel=argExp.eval(this);
        try {
          if (i < argumentNames.length) {
            String argName=argumentNames[i];
            mc.setLocalVar(argName,argModel);
          }
 else {
            ((SimpleSequence)unknownVars).add(argModel);
          }
        }
 catch (        RuntimeException re) {
          throw new _MiscTemplateException(re,this);
        }
      }
    }
    if (catchAll != null) {
      mc.setLocalVar(catchAll,unknownVars);
    }
    ArrayList prevLocalContextStack=localContextStack;
    localContextStack=null;
    Namespace prevNamespace=currentNamespace;
    currentNamespace=(Namespace)macroToNamespaceLookup.get(macro);
    currentMacroContext=mc;
    final Configurable prevParent;
    final boolean parentReplacementOn=getConfiguration().getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_22;
    if (parentReplacementOn) {
      prevParent=getParent();
    }
 else {
      prevParent=null;
    }
    try {
      mc.runMacro(this);
    }
 catch (    ReturnInstruction.Return re) {
    }
catch (    TemplateException te) {
      handleTemplateException(te);
    }
 finally {
      currentMacroContext=previousMacroContext;
      localContextStack=prevLocalContextStack;
      currentNamespace=prevNamespace;
      if (parentReplacementOn) {
        setParent(prevParent);
      }
    }
  }
  finally {
    popElement();
  }
}