Program: 15785
Project: 15785
Buggy source:
void sanityCheck(Environment env) throws TemplateException {
  boolean resolvedAnArg, hasUnresolvedArg;
  Expression firstUnresolvedExpression;
  InvalidReferenceException firstReferenceException;
  do {
    firstUnresolvedExpression=null;
    firstReferenceException=null;
    resolvedAnArg=hasUnresolvedArg=false;
    for (int i=0; i < argumentNames.length; ++i) {
      String argName=argumentNames[i];
      if (localVars.get(argName) == null) {
        Expression valueExp=(Expression)args.get(argName);
        if (valueExp != null) {
          try {
            TemplateModel tm=valueExp.getAsTemplateModel(env);
            if (tm == null) {
              if (!hasUnresolvedArg) {
                firstUnresolvedExpression=valueExp;
                hasUnresolvedArg=true;
              }
            }
 else {
              localVars.put(argName,tm);
              resolvedAnArg=true;
            }
          }
 catch (          InvalidReferenceException e) {
            if (!hasUnresolvedArg) {
              hasUnresolvedArg=true;
              firstReferenceException=e;
            }
          }
        }
 else         if (!env.isClassicCompatible()) {
          String desc="String_Node_Str" + StringUtil.jQuote(name) + "String_Node_Str"+ StringUtil.jQuote(argName)+ "String_Node_Str"+ (i + 1)+ "String_Node_Str";
          String hint;
          if (localVars.containsKey(argName)) {
            desc+="String_Node_Str";
            hint="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str";
          }
 else {
            desc+="String_Node_Str";
            hint="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + StringUtil.encloseAsTag(getTemplate(),"String_Node_Str") + "String_Node_Str";
          }
          throw new TemplateException(MessageUtil.decorateErrorDescription(desc,null,hint),env);
        }
      }
    }
  }
 while (resolvedAnArg && hasUnresolvedArg);
  if (hasUnresolvedArg) {
    if (firstReferenceException != null) {
      throw firstReferenceException;
    }
 else     if (!env.isClassicCompatible()) {
      firstUnresolvedExpression.newInvalidReferenceException();
    }
  }
}

Fixed version (ground truth):
void sanityCheck(Environment env) throws TemplateException {
  boolean resolvedAnArg, hasUnresolvedArg;
  Expression firstUnresolvedExpression;
  InvalidReferenceException firstReferenceException;
  do {
    firstUnresolvedExpression=null;
    firstReferenceException=null;
    resolvedAnArg=hasUnresolvedArg=false;
    for (int i=0; i < argumentNames.length; ++i) {
      String argName=argumentNames[i];
      if (localVars.get(argName) == null) {
        Expression valueExp=(Expression)args.get(argName);
        if (valueExp != null) {
          try {
            TemplateModel tm=valueExp.getAsTemplateModel(env);
            if (tm == null) {
              if (!hasUnresolvedArg) {
                firstUnresolvedExpression=valueExp;
                hasUnresolvedArg=true;
              }
            }
 else {
              localVars.put(argName,tm);
              resolvedAnArg=true;
            }
          }
 catch (          InvalidReferenceException e) {
            if (!hasUnresolvedArg) {
              hasUnresolvedArg=true;
              firstReferenceException=e;
            }
          }
        }
 else         if (!env.isClassicCompatible()) {
          String desc="String_Node_Str" + StringUtil.jQuote(name) + "String_Node_Str"+ StringUtil.jQuote(argName)+ "String_Node_Str"+ (i + 1)+ "String_Node_Str";
          String hint;
          if (localVars.containsKey(argName)) {
            desc+="String_Node_Str";
            hint="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str";
          }
 else {
            desc+="String_Node_Str";
            hint="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + StringUtil.encloseAsTag(getTemplate(),"String_Node_Str") + "String_Node_Str";
          }
          throw new TemplateException(MessageUtil.decorateErrorDescription(desc,null,hint),env);
        }
      }
    }
  }
 while (resolvedAnArg && hasUnresolvedArg);
  if (hasUnresolvedArg) {
    if (firstReferenceException != null) {
      throw firstReferenceException;
    }
 else     if (!env.isClassicCompatible()) {
      throw firstUnresolvedExpression.newInvalidReferenceException();
    }
  }
}