Program: 10838
Project: 10838
Buggy source:
public static void setOptionVariableValues(ServiceCommand serviceCommand,Map<String,String> variableToValueMap){
  CommandOptions commandOptions=serviceCommand.getOptions();
  if (commandOptions == null || commandOptions.getOptions() == null) {
    return;
  }
  String options=commandOptions.getOptions();
  StringBuffer variableBuffer=null;
  StringBuffer resolvedOptions=new StringBuffer(options);
  int dollarSignIndex=-1;
  for (int i=0; i < resolvedOptions.length(); ) {
    boolean inserted=false;
    if (resolvedOptions.charAt(i) == '$') {
      dollarSignIndex=i;
      variableBuffer=new StringBuffer();
    }
 else     if ((resolvedOptions.charAt(i) == '}' || i == resolvedOptions.length() - 1) && variableBuffer != null) {
      if (variableBuffer.length() > 0) {
        String variable=variableBuffer.toString();
        String value=variableToValueMap.get(variable);
        int endingIndex=i + 1;
        if (value != null && dollarSignIndex >= 0 && (endingIndex <= resolvedOptions.length())) {
          resolvedOptions.replace(dollarSignIndex,endingIndex,"String_Node_Str");
          resolvedOptions.insert(dollarSignIndex,value);
          i=dollarSignIndex + value.length();
          inserted=true;
        }
      }
      variableBuffer=null;
      dollarSignIndex=-1;
    }
 else     if (variableBuffer != null && resolvedOptions.charAt(i) != '{') {
      variableBuffer.append(resolvedOptions.charAt(i));
    }
    if (!inserted) {
      i++;
    }
  }
  CommandOptions resolvedOp=new CommandOptions();
  resolvedOp.setOptions(resolvedOptions.toString());
  serviceCommand.setOptions(resolvedOp);
}

Fixed version (ground truth):
public static void setOptionVariableValues(ServiceCommand serviceCommand,Map<String,String> variableToValueMap){
  CommandOptions commandOptions=serviceCommand.getOptions();
  if (commandOptions == null || commandOptions.getOptions() == null) {
    return;
  }
  String options=commandOptions.getOptions();
  StringBuffer variableBuffer=null;
  StringBuffer resolvedOptions=new StringBuffer(options);
  int dollarSignIndex=-1;
  for (int i=0; i < resolvedOptions.length(); ) {
    boolean inserted=false;
    if ((resolvedOptions.charAt(i) == '$') && i + 1 < resolvedOptions.length() && (resolvedOptions.charAt(i + 1) == '{')) {
      dollarSignIndex=i;
      i++;
      variableBuffer=new StringBuffer();
    }
 else     if ((resolvedOptions.charAt(i) == '}') && variableBuffer != null) {
      if (variableBuffer.length() > 0) {
        String variable=variableBuffer.toString();
        String value=variableToValueMap.get(variable);
        int endingIndex=i + 1;
        if (value != null && dollarSignIndex >= 0 && (endingIndex <= resolvedOptions.length())) {
          resolvedOptions.replace(dollarSignIndex,endingIndex,"String_Node_Str");
          resolvedOptions.insert(dollarSignIndex,value);
          i=dollarSignIndex + value.length();
          inserted=true;
        }
      }
      variableBuffer=null;
      dollarSignIndex=-1;
    }
 else     if (variableBuffer != null) {
      variableBuffer.append(resolvedOptions.charAt(i));
    }
    if (!inserted) {
      i++;
    }
  }
  CommandOptions resolvedOp=new CommandOptions();
  resolvedOp.setOptions(resolvedOptions.toString());
  serviceCommand.setOptions(resolvedOp);
}