Program: 168979
Project: 168979
Buggy source:
@Override public Map<String,String> appendExtendedSql(StringBuilder sqlSb,DbmsStatementType statementType,boolean isSubquery,boolean isEmbedded,StringBuilder withClause,String limit,String offset,String[] returningColumns,Map<DbmsModificationState,String> includedModificationStates){
  boolean requiresOld=includedModificationStates != null && includedModificationStates.containsKey(DbmsModificationState.OLD);
  if (requiresOld) {
    Map<String,String> dbmsModificationStateQueries=new HashMap<String,String>();
    StringBuilder sb=new StringBuilder(sqlSb.length() + 30);
    if (statementType == DbmsStatementType.INSERT) {
      StringBuilder newValuesSb=new StringBuilder();
      String newValuesTableName="String_Node_Str" + includedModificationStates.get(DbmsModificationState.OLD);
      newValuesSb.append("String_Node_Str");
      newValuesSb.append(sqlSb);
      newValuesSb.append("String_Node_Str");
      dbmsModificationStateQueries.put("String_Node_Str" + includedModificationStates.get(DbmsModificationState.OLD),newValuesSb.toString());
      String needle="String_Node_Str";
      int startIndex=indexOfIgnoreCase(sqlSb,needle) + needle.length() + 1;
      int endIndex=sqlSb.indexOf("String_Node_Str",startIndex);
      endIndex=indexOfOrEnd(sqlSb,'(',startIndex,endIndex);
      String table=sqlSb.substring(startIndex,endIndex);
      sb.append("String_Node_Str");
      sb.append(table);
      sb.append("String_Node_Str");
      sb.append("String_Node_Str");
      sb.append(newValuesTableName);
    }
 else {
      sb.append("String_Node_Str");
      sb.append(sqlSb);
      sb.append("String_Node_Str");
    }
    sqlSb.setLength(0);
    if (isSubquery) {
      sqlSb.append('(');
    }
    sqlSb.append("String_Node_Str");
    for (int i=0; i < returningColumns.length; i++) {
      if (i != 0) {
        sqlSb.append(',');
      }
      sqlSb.append(returningColumns[i]);
    }
    sqlSb.append("String_Node_Str");
    sqlSb.append(includedModificationStates.get(DbmsModificationState.OLD));
    dbmsModificationStateQueries.put(includedModificationStates.get(DbmsModificationState.OLD),sb.toString());
    if (isSubquery) {
      sqlSb.append(')');
    }
    return dbmsModificationStateQueries;
  }
  boolean needsReturningWrapper=isEmbedded && (returningColumns != null || statementType != DbmsStatementType.SELECT);
  if (needsReturningWrapper || withClause != null && (statementType != DbmsStatementType.SELECT)) {
    if (isSubquery) {
      sqlSb.insert(0,'(');
    }
    if (limit != null) {
      appendLimit(sqlSb,isSubquery,limit,offset);
    }
    String[] columns;
    if (returningColumns == null) {
      columns=new String[]{"String_Node_Str"};
    }
 else {
      columns=returningColumns;
    }
    if (needsReturningWrapper) {
      applyQueryReturning(sqlSb,statementType,withClause,columns);
    }
 else {
      applyQueryReturning(sqlSb,statementType,withClause,columns);
    }
    if (isSubquery) {
      sqlSb.append(')');
    }
    return null;
  }
  if (isSubquery) {
    sqlSb.insert(0,'(');
  }
  if (withClause != null) {
    sqlSb.insert(indexOfIgnoreCase(sqlSb,"String_Node_Str"),withClause);
  }
  if (limit != null) {
    appendLimit(sqlSb,isSubquery,limit,offset);
  }
  if (isSubquery) {
    sqlSb.append(')');
  }
  return null;
}

Fixed version (ground truth):
@Override public Map<String,String> appendExtendedSql(StringBuilder sqlSb,DbmsStatementType statementType,boolean isSubquery,boolean isEmbedded,StringBuilder withClause,String limit,String offset,String[] returningColumns,Map<DbmsModificationState,String> includedModificationStates){
  boolean requiresOld=includedModificationStates != null && includedModificationStates.containsKey(DbmsModificationState.OLD);
  if (requiresOld) {
    Map<String,String> dbmsModificationStateQueries=new LinkedHashMap<String,String>();
    StringBuilder sb=new StringBuilder(sqlSb.length() + 30);
    if (statementType == DbmsStatementType.INSERT) {
      StringBuilder newValuesSb=new StringBuilder();
      String newValuesTableName="String_Node_Str" + includedModificationStates.get(DbmsModificationState.OLD);
      newValuesSb.append("String_Node_Str");
      newValuesSb.append(sqlSb);
      newValuesSb.append("String_Node_Str");
      dbmsModificationStateQueries.put("String_Node_Str" + includedModificationStates.get(DbmsModificationState.OLD),newValuesSb.toString());
      String needle="String_Node_Str";
      int startIndex=indexOfIgnoreCase(sqlSb,needle) + needle.length() + 1;
      int endIndex=sqlSb.indexOf("String_Node_Str",startIndex);
      endIndex=indexOfOrEnd(sqlSb,'(',startIndex,endIndex);
      String table=sqlSb.substring(startIndex,endIndex);
      sb.append("String_Node_Str");
      sb.append(table);
      sb.append("String_Node_Str");
      sb.append("String_Node_Str");
      sb.append(newValuesTableName);
    }
 else {
      sb.append("String_Node_Str");
      sb.append(sqlSb);
      sb.append("String_Node_Str");
    }
    sqlSb.setLength(0);
    if (isSubquery) {
      sqlSb.append('(');
    }
    sqlSb.append("String_Node_Str");
    for (int i=0; i < returningColumns.length; i++) {
      if (i != 0) {
        sqlSb.append(',');
      }
      sqlSb.append(returningColumns[i]);
    }
    sqlSb.append("String_Node_Str");
    sqlSb.append(includedModificationStates.get(DbmsModificationState.OLD));
    dbmsModificationStateQueries.put(includedModificationStates.get(DbmsModificationState.OLD),sb.toString());
    if (isSubquery) {
      sqlSb.append(')');
    }
    return dbmsModificationStateQueries;
  }
  boolean needsReturningWrapper=isEmbedded && (returningColumns != null || statementType != DbmsStatementType.SELECT);
  if (needsReturningWrapper || withClause != null && (statementType != DbmsStatementType.SELECT)) {
    if (isSubquery) {
      sqlSb.insert(0,'(');
    }
    if (limit != null) {
      appendLimit(sqlSb,isSubquery,limit,offset);
    }
    String[] columns;
    if (returningColumns == null) {
      columns=new String[]{"String_Node_Str"};
    }
 else {
      columns=returningColumns;
    }
    if (needsReturningWrapper) {
      applyQueryReturning(sqlSb,statementType,withClause,columns);
    }
 else {
      applyQueryReturning(sqlSb,statementType,withClause,columns);
    }
    if (isSubquery) {
      sqlSb.append(')');
    }
    return null;
  }
  if (isSubquery) {
    sqlSb.insert(0,'(');
  }
  if (withClause != null) {
    sqlSb.insert(indexOfIgnoreCase(sqlSb,"String_Node_Str"),withClause);
  }
  if (limit != null) {
    appendLimit(sqlSb,isSubquery,limit,offset);
  }
  if (isSubquery) {
    sqlSb.append(')');
  }
  return null;
}