Program: 64905
Project: 64905
Buggy source:
public java.sql.Timestamp convertStringToTimestamp(String sourceString,QName schemaType){
  XMLGregorianCalendar xmlGregorianCalender=null;
  try {
    xmlGregorianCalender=convertStringToXMLGregorianCalendar(sourceString);
  }
 catch (  Exception ex) {
    if (XMLConstants.DATE_QNAME.equals(schemaType)) {
      throw ConversionException.incorrectDateFormat(sourceString);
    }
 else     if (XMLConstants.TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampTimeFormat(sourceString);
    }
 else     if (XMLConstants.G_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGDayFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthDayFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearMonthFormat(sourceString);
    }
 else     if (XMLConstants.DURATION_QNAME.equals(schemaType)) {
      throw new IllegalArgumentException();
    }
 else {
      throw XMLConversionException.incorrectTimestampDateTimeFormat(sourceString);
    }
  }
  GregorianCalendar cal=xmlGregorianCalender.toGregorianCalendar();
  if (xmlGregorianCalender.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
    cal.setTimeZone(getTimeZone());
  }
  QName calendarQName=xmlGregorianCalender.getXMLSchemaType();
  if (!calendarQName.equals(schemaType)) {
    if (XMLConstants.DATE_QNAME.equals(schemaType)) {
      if (calendarQName.equals(XMLConstants.DATE_TIME_QNAME)) {
        cal.clear(Calendar.HOUR_OF_DAY);
        cal.clear(Calendar.MINUTE);
        cal.clear(Calendar.SECOND);
        cal.clear(Calendar.MILLISECOND);
        return Helper.timestampFromCalendar(cal);
      }
 else {
        throw ConversionException.incorrectDateFormat(sourceString);
      }
    }
 else     if (XMLConstants.TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampTimeFormat(sourceString);
    }
 else     if (XMLConstants.G_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGDayFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthDayFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearMonthFormat(sourceString);
    }
 else     if (XMLConstants.DURATION_QNAME.equals(schemaType)) {
      throw new IllegalArgumentException();
    }
 else     if (XMLConstants.DATE_TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampDateTimeFormat(sourceString);
    }
  }
  Timestamp timestamp=Helper.timestampFromCalendar(cal);
  int decimalIndex=sourceString.lastIndexOf('.');
  if (-1 == decimalIndex) {
    return timestamp;
  }
 else {
    int timeZoneIndex=sourceString.lastIndexOf(GMT_SUFFIX);
    if (-1 == timeZoneIndex) {
      timeZoneIndex=sourceString.lastIndexOf('-');
      if (timeZoneIndex < decimalIndex) {
        timeZoneIndex=-1;
      }
      if (-1 == timeZoneIndex) {
        timeZoneIndex=sourceString.lastIndexOf('+');
      }
    }
    String nsString;
    if (-1 == timeZoneIndex) {
      nsString=sourceString.substring(decimalIndex + 1);
    }
 else {
      nsString=sourceString.substring((decimalIndex + 1),timeZoneIndex);
    }
    double ns=Long.valueOf(nsString).doubleValue();
    ns=ns * Math.pow(10,9 - nsString.length());
    timestamp.setNanos((int)ns);
    return timestamp;
  }
}

Fixed version (ground truth):
public java.sql.Timestamp convertStringToTimestamp(String sourceString,QName schemaType){
  XMLGregorianCalendar xmlGregorianCalender=null;
  try {
    xmlGregorianCalender=convertStringToXMLGregorianCalendar(sourceString);
  }
 catch (  Exception ex) {
    if (XMLConstants.DATE_QNAME.equals(schemaType)) {
      throw ConversionException.incorrectDateFormat(sourceString);
    }
 else     if (XMLConstants.TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampTimeFormat(sourceString);
    }
 else     if (XMLConstants.G_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGDayFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthDayFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearMonthFormat(sourceString);
    }
 else     if (XMLConstants.DURATION_QNAME.equals(schemaType)) {
      throw new IllegalArgumentException();
    }
 else {
      throw XMLConversionException.incorrectTimestampDateTimeFormat(sourceString);
    }
  }
  GregorianCalendar cal=xmlGregorianCalender.toGregorianCalendar();
  if (xmlGregorianCalender.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
    cal.setTimeZone(getTimeZone());
  }
  QName calendarQName=xmlGregorianCalender.getXMLSchemaType();
  if (!calendarQName.equals(schemaType)) {
    if (XMLConstants.DATE_QNAME.equals(schemaType)) {
      if (calendarQName.equals(XMLConstants.DATE_TIME_QNAME)) {
        cal.clear(Calendar.HOUR_OF_DAY);
        cal.clear(Calendar.MINUTE);
        cal.clear(Calendar.SECOND);
        cal.clear(Calendar.MILLISECOND);
        return Helper.timestampFromCalendar(cal);
      }
 else {
        throw ConversionException.incorrectDateFormat(sourceString);
      }
    }
 else     if (XMLConstants.TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampTimeFormat(sourceString);
    }
 else     if (XMLConstants.G_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGDayFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthFormat(sourceString);
    }
 else     if (XMLConstants.G_MONTH_DAY_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGMonthDayFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearFormat(sourceString);
    }
 else     if (XMLConstants.G_YEAR_MONTH_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectGYearMonthFormat(sourceString);
    }
 else     if (XMLConstants.DURATION_QNAME.equals(schemaType)) {
      throw new IllegalArgumentException();
    }
 else     if (XMLConstants.DATE_TIME_QNAME.equals(schemaType)) {
      throw XMLConversionException.incorrectTimestampDateTimeFormat(sourceString);
    }
  }
  Timestamp timestamp=Helper.timestampFromCalendar(cal);
  String trimmedSourceString=sourceString.trim();
  int decimalIndex=trimmedSourceString.lastIndexOf('.');
  if (-1 == decimalIndex) {
    return timestamp;
  }
 else {
    int timeZoneIndex=trimmedSourceString.lastIndexOf(GMT_SUFFIX);
    if (-1 == timeZoneIndex) {
      timeZoneIndex=trimmedSourceString.lastIndexOf('-');
      if (timeZoneIndex < decimalIndex) {
        timeZoneIndex=-1;
      }
      if (-1 == timeZoneIndex) {
        timeZoneIndex=trimmedSourceString.lastIndexOf('+');
      }
    }
    String nsString;
    if (-1 == timeZoneIndex) {
      nsString=trimmedSourceString.substring(decimalIndex + 1);
    }
 else {
      nsString=trimmedSourceString.substring((decimalIndex + 1),timeZoneIndex);
    }
    double ns=Long.valueOf(nsString).doubleValue();
    ns=ns * Math.pow(10,9 - nsString.length());
    timestamp.setNanos((int)ns);
    return timestamp;
  }
}