Program: 15658
Project: 15658
Buggy source:
private TemplateDateFormat getTemplateDateFormat(int dateType,boolean useSysDefTZ,String formatDescriptor,String sourceCfgSetting) throws TemplateModelException, UnknownDateTypeFormattingUnsupportedException {
  final int formatDescriptionLen=formatDescriptor.length();
  final TimeZone timeZone=useSysDefTZ ? getSystemDefaultTimeZone() : getTimeZone();
  TemplateDateFormatFactory templateDateFormatFactory;
  if (formatDescriptionLen > 1 && formatDescriptor.charAt(0) == 'x' && formatDescriptor.charAt(1) == 's') {
    templateDateFormatFactory=useSysDefTZ ? cachedXSTemplateDateFormatFactorySysDefTZ : cachedXSTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new XSTemplateDateFormatFactory(timeZone);
      if (useSysDefTZ) {
        cachedXSTemplateDateFormatFactorySysDefTZ=(XSTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedXSTemplateDateFormatFactory=(XSTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
 else   if (formatDescriptionLen > 2 && formatDescriptor.charAt(0) == 'i' && formatDescriptor.charAt(1) == 's' && formatDescriptor.charAt(2) == 'o') {
    templateDateFormatFactory=useSysDefTZ ? cachedISOTemplateDateFormatFactorySysDefTZ : cachedISOTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new ISOTemplateDateFormatFactory(timeZone);
      if (useSysDefTZ) {
        cachedISOTemplateDateFormatFactorySysDefTZ=(ISOTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedISOTemplateDateFormatFactory=(ISOTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
 else {
    templateDateFormatFactory=useSysDefTZ ? cachedJavaTemplateDateFormatFactorySysDefTZ : cachedJavaTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new JavaTemplateDateFormatFactory(timeZone,getLocale());
      if (useSysDefTZ) {
        cachedJavaTemplateDateFormatFactorySysDefTZ=(JavaTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedJavaTemplateDateFormatFactory=(JavaTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
  try {
    return templateDateFormatFactory.get(dateType,formatDescriptor);
  }
 catch (  ParseException e) {
    throw new _TemplateModelException(e.getCause(),new Object[]{(sourceCfgSetting == null ? (Object)"String_Node_Str" : new Object[]{"String_Node_Str",sourceCfgSetting,"String_Node_Str"}),new _DelayedJQuote(formatDescriptor),"String_Node_Str",e.getMessage()});
  }
}

Fixed version (ground truth):
private TemplateDateFormat getTemplateDateFormat(int dateType,boolean zonelessInput,boolean useSysDefTZ,String formatDescriptor,String sourceCfgSetting) throws TemplateModelException, UnknownDateTypeFormattingUnsupportedException {
  final int formatDescriptionLen=formatDescriptor.length();
  final TimeZone timeZone=useSysDefTZ ? getSystemDefaultTimeZone() : getTimeZone();
  TemplateDateFormatFactory templateDateFormatFactory;
  if (formatDescriptionLen > 1 && formatDescriptor.charAt(0) == 'x' && formatDescriptor.charAt(1) == 's') {
    templateDateFormatFactory=useSysDefTZ ? cachedXSTemplateDateFormatFactorySysDefTZ : cachedXSTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new XSTemplateDateFormatFactory(timeZone);
      if (useSysDefTZ) {
        cachedXSTemplateDateFormatFactorySysDefTZ=(XSTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedXSTemplateDateFormatFactory=(XSTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
 else   if (formatDescriptionLen > 2 && formatDescriptor.charAt(0) == 'i' && formatDescriptor.charAt(1) == 's' && formatDescriptor.charAt(2) == 'o') {
    templateDateFormatFactory=useSysDefTZ ? cachedISOTemplateDateFormatFactorySysDefTZ : cachedISOTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new ISOTemplateDateFormatFactory(timeZone);
      if (useSysDefTZ) {
        cachedISOTemplateDateFormatFactorySysDefTZ=(ISOTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedISOTemplateDateFormatFactory=(ISOTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
 else {
    templateDateFormatFactory=useSysDefTZ ? cachedJavaTemplateDateFormatFactorySysDefTZ : cachedJavaTemplateDateFormatFactory;
    if (templateDateFormatFactory == null) {
      templateDateFormatFactory=new JavaTemplateDateFormatFactory(timeZone,getLocale());
      if (useSysDefTZ) {
        cachedJavaTemplateDateFormatFactorySysDefTZ=(JavaTemplateDateFormatFactory)templateDateFormatFactory;
      }
 else {
        cachedJavaTemplateDateFormatFactory=(JavaTemplateDateFormatFactory)templateDateFormatFactory;
      }
    }
  }
  try {
    return templateDateFormatFactory.get(dateType,zonelessInput,formatDescriptor);
  }
 catch (  ParseException e) {
    throw new _TemplateModelException(e.getCause(),new Object[]{(sourceCfgSetting == null ? (Object)"String_Node_Str" : new Object[]{"String_Node_Str",sourceCfgSetting,"String_Node_Str"}),new _DelayedJQuote(formatDescriptor),"String_Node_Str",e.getMessage()});
  }
}