Program: 63473
Project: 63473
Buggy source:
/** 
 * INTERNAL: Parse the query string for # markers for custom query based on a query language. This is used by SQLCall and XQuery call, but can be reused by other query languages.
 */
public void translateCustomQuery(){
  if (this.shouldProcessTokenInQuotes) {
    if (getQueryString().indexOf(this.query.getParameterDelimiter()) == -1) {
      if (this.getQuery().shouldBindAllParameters() && getQueryString().indexOf("String_Node_Str") == -1) {
        return;
      }
      translatePureSQLCustomQuery();
      return;
    }
  }
 else {
    if (!hasArgumentMark(getQueryString(),this.query.getParameterDelimiterChar())) {
      if (this.getQuery().shouldBindAllParameters() && !hasArgumentMark(getQueryString(),'?')) {
        return;
      }
      translatePureSQLCustomQuery();
      return;
    }
  }
  int lastIndex=0;
  String queryString=getQueryString();
  Writer writer=new CharArrayWriter(queryString.length() + 50);
  try {
    while (lastIndex != -1) {
      int poundIndex=queryString.indexOf(this.query.getParameterDelimiterChar(),lastIndex);
      String token;
      if (poundIndex == -1) {
        token=queryString.substring(lastIndex,queryString.length());
        lastIndex=-1;
      }
 else {
        if (this.shouldProcessTokenInQuotes) {
          token=queryString.substring(lastIndex,poundIndex);
        }
 else {
          boolean hasPairedQuoteBeforePound=true;
          int quotePairIndex=poundIndex;
          do {
            quotePairIndex=queryString.lastIndexOf('\'',quotePairIndex - 1);
            if (quotePairIndex != -1 && quotePairIndex > lastIndex) {
              hasPairedQuoteBeforePound=!hasPairedQuoteBeforePound;
            }
 else {
              break;
            }
          }
 while (true);
          int endQuoteIndex=-1;
          if (!hasPairedQuoteBeforePound) {
            endQuoteIndex=queryString.indexOf('\'',poundIndex + 1);
          }
          if (endQuoteIndex != -1) {
            token=queryString.substring(lastIndex,endQuoteIndex + 1);
            poundIndex=-1;
            lastIndex=endQuoteIndex + 1;
          }
 else {
            token=queryString.substring(lastIndex,poundIndex);
            lastIndex=poundIndex + 1;
          }
        }
      }
      writer.write(token);
      if (poundIndex != -1) {
        int wordEndIndex=poundIndex + 1;
        while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) {
          wordEndIndex=wordEndIndex + 1;
        }
        if (queryString.charAt(poundIndex + 1) == this.query.getParameterDelimiterChar()) {
          if (queryString.charAt(poundIndex + 2) == this.query.getParameterDelimiterChar()) {
            if (queryString.charAt(poundIndex + 3) == this.query.getParameterDelimiterChar()) {
              String fieldName=queryString.substring(poundIndex + 4,wordEndIndex);
              DatabaseField field=createField(fieldName);
              appendInOut(writer,field);
            }
 else {
              String fieldName=queryString.substring(poundIndex + 3,wordEndIndex);
              DatabaseField field=createField(fieldName);
              appendOut(writer,field);
            }
          }
 else {
            String fieldName=queryString.substring(poundIndex + 2,wordEndIndex);
            DatabaseField field=createField(fieldName);
            appendModify(writer,field);
          }
        }
 else {
          String fieldName=queryString.substring(poundIndex + 1,wordEndIndex);
          DatabaseField field=createField(fieldName);
          appendIn(writer,field);
        }
        lastIndex=wordEndIndex;
      }
    }
    setQueryString(writer.toString());
  }
 catch (  IOException exception) {
    throw ValidationException.fileError(exception);
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Parse the query string for # markers for custom query based on a query language. This is used by SQLCall and XQuery call, but can be reused by other query languages.
 */
public void translateCustomQuery(){
  if (this.shouldProcessTokenInQuotes) {
    if (getQueryString().indexOf(this.query.getParameterDelimiter()) == -1) {
      if (this.getQuery().shouldBindAllParameters() && getQueryString().indexOf("String_Node_Str") == -1) {
        return;
      }
      translatePureSQLCustomQuery();
      return;
    }
  }
 else {
    if (!hasArgumentMark(getQueryString(),this.query.getParameterDelimiterChar(),'\'') || !hasArgumentMark(getQueryString(),this.query.getParameterDelimiterChar(),'\"') || !hasArgumentMark(getQueryString(),this.query.getParameterDelimiterChar(),'`')) {
      if (this.getQuery().shouldBindAllParameters() && !hasArgumentMark(getQueryString(),'?','\'')) {
        return;
      }
      translatePureSQLCustomQuery();
      return;
    }
  }
  int lastIndex=0;
  String queryString=getQueryString();
  Writer writer=new CharArrayWriter(queryString.length() + 50);
  try {
    while (lastIndex != -1) {
      int poundIndex=queryString.indexOf(this.query.getParameterDelimiterChar(),lastIndex);
      String token;
      if (poundIndex == -1) {
        token=queryString.substring(lastIndex,queryString.length());
        lastIndex=-1;
      }
 else {
        if (this.shouldProcessTokenInQuotes) {
          token=queryString.substring(lastIndex,poundIndex);
        }
 else {
          boolean hasPairedQuoteBeforePound=true;
          int quotePairIndex=poundIndex;
          do {
            quotePairIndex=queryString.lastIndexOf('\'',quotePairIndex - 1);
            if (quotePairIndex != -1 && quotePairIndex > lastIndex) {
              hasPairedQuoteBeforePound=!hasPairedQuoteBeforePound;
            }
 else {
              break;
            }
          }
 while (true);
          int endQuoteIndex=-1;
          if (!hasPairedQuoteBeforePound) {
            endQuoteIndex=queryString.indexOf('\'',poundIndex + 1);
          }
          if (endQuoteIndex != -1) {
            token=queryString.substring(lastIndex,endQuoteIndex + 1);
            poundIndex=-1;
            lastIndex=endQuoteIndex + 1;
          }
 else {
            token=queryString.substring(lastIndex,poundIndex);
            lastIndex=poundIndex + 1;
          }
        }
      }
      writer.write(token);
      if (poundIndex != -1) {
        int wordEndIndex=poundIndex + 1;
        while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) {
          wordEndIndex=wordEndIndex + 1;
        }
        if (queryString.charAt(poundIndex + 1) == this.query.getParameterDelimiterChar()) {
          if (queryString.charAt(poundIndex + 2) == this.query.getParameterDelimiterChar()) {
            if (queryString.charAt(poundIndex + 3) == this.query.getParameterDelimiterChar()) {
              String fieldName=queryString.substring(poundIndex + 4,wordEndIndex);
              DatabaseField field=createField(fieldName);
              appendInOut(writer,field);
            }
 else {
              String fieldName=queryString.substring(poundIndex + 3,wordEndIndex);
              DatabaseField field=createField(fieldName);
              appendOut(writer,field);
            }
          }
 else {
            String fieldName=queryString.substring(poundIndex + 2,wordEndIndex);
            DatabaseField field=createField(fieldName);
            appendModify(writer,field);
          }
        }
 else {
          String fieldName=queryString.substring(poundIndex + 1,wordEndIndex);
          DatabaseField field=createField(fieldName);
          appendIn(writer,field);
        }
        lastIndex=wordEndIndex;
      }
    }
    setQueryString(writer.toString());
  }
 catch (  IOException exception) {
    throw ValidationException.fileError(exception);
  }
}