Program: 42361
Project: 42361
Buggy source:
List<XValue> expand(String arg,boolean bExpandWild,boolean bExpandWords) throws IOException, CoreException {
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    r.add(new XValue(parseXExpr(arg.substring(2,arg.length() - 2))));
    return r;
  }
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    r.add(new XValue(parseXCmd(arg.substring(3,arg.length() - 1))));
    return r;
  }
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    String res=expandSubproc(arg.substring(2,arg.length() - 1));
    if (bExpandWords)     for (    String w : res.split("String_Node_Str"))     r.add(new XValue(w));
 else     r.add(new XValue(res));
    return r;
  }
  Result result=new Result();
  char cQuote=0;
  char c;
  int i;
  for (i=0; i < arg.length(); i++) {
    c=arg.charAt(i);
    if (c == '\'' || c == '"') {
      if (cQuote == c)       cQuote=0;
 else       if (cQuote == 0)       cQuote=c;
    }
    if (c == '\\') {
      if (i < arg.length())       result.append(arg.charAt(++i));
      continue;
    }
    if (cQuote != '\'' && c == '$') {
      if (++i == arg.length())       break;
      StringBuffer sbv=new StringBuffer();
      if (arg.charAt(i) == '{') {
        i=readToMatching(arg,i,sbv,'}');
      }
 else       if (arg.charAt(i) == '(') {
        sbv.append('(');
        i=readToMatching(arg,i,sbv,')');
        sbv.append(')');
      }
 else {
        c=arg.charAt(i);
        if (c == '?' || c == '@' || c == '$' || c == '#' || c == '*' || c == '!' || Character.isDigit(c)) {
          boolean bKeepGoing;
          do {
            bKeepGoing=false;
            sbv.append(c);
            if (Character.isDigit(c)) {
              if (i < arg.length() - 1 && Character.isDigit(c=arg.charAt(i + 1))) {
                i++;
                bKeepGoing=true;
              }
            }
          }
 while (bKeepGoing);
        }
 else {
          for (; i < arg.length(); i++) {
            c=arg.charAt(i);
            if (Util.isIdentifier(c))             sbv.append(c);
 else {
              i--;
              break;
            }
          }
        }
      }
      String var=sbv.toString();
      if (!Util.isBlank(var)) {
        XValue value=null;
        if (var.equals("String_Node_Str")) {
          result.add(mArgs);
        }
 else         value=extractSingle(var,cQuote != '\0');
        if (value != null)         result.append(value);
      }
    }
 else     result.append(c);
  }
  result.flush();
  if (!bExpandWild)   return result.getResult();
  ArrayList<XValue> result2=new ArrayList<XValue>();
  for (  XValue v : result.getResult()) {
    List<XValue> r=expandWild(v);
    if (r != null)     result2.addAll(r);
  }
  return result2;
}

Fixed version (ground truth):
List<XValue> expand(String arg,boolean bExpandWild,boolean bExpandWords) throws IOException, CoreException {
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    r.add(new XValue(parseXExpr(arg.substring(2,arg.length() - 2))));
    return r;
  }
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    r.add(new XValue(parseXCmd(arg.substring(3,arg.length() - 1))));
    return r;
  }
  if (arg.startsWith("String_Node_Str") && arg.endsWith("String_Node_Str")) {
    List<XValue> r=new ArrayList<XValue>(1);
    String res=expandSubproc(arg.substring(2,arg.length() - 1));
    if (bExpandWords)     for (    String w : res.split("String_Node_Str"))     r.add(new XValue(w));
 else     r.add(new XValue(res));
    return r;
  }
  Result result=new Result();
  char cQuote=0;
  char c;
  int i;
  for (i=0; i < arg.length(); i++) {
    c=arg.charAt(i);
    if (c == '\'' || c == '"') {
      if (cQuote == c)       cQuote=0;
 else       if (cQuote == 0)       cQuote=c;
    }
    if (c == '\\') {
      result.append(c);
      if (i < arg.length())       result.append(arg.charAt(++i));
      continue;
    }
    if (cQuote != '\'' && c == '$') {
      if (++i == arg.length())       break;
      StringBuffer sbv=new StringBuffer();
      if (arg.charAt(i) == '{') {
        i=readToMatching(arg,i,sbv,'}');
      }
 else       if (arg.charAt(i) == '(') {
        sbv.append('(');
        i=readToMatching(arg,i,sbv,')');
        sbv.append(')');
      }
 else {
        c=arg.charAt(i);
        if (c == '?' || c == '@' || c == '$' || c == '#' || c == '*' || c == '!' || Character.isDigit(c)) {
          boolean bKeepGoing;
          do {
            bKeepGoing=false;
            sbv.append(c);
            if (Character.isDigit(c)) {
              if (i < arg.length() - 1 && Character.isDigit(c=arg.charAt(i + 1))) {
                i++;
                bKeepGoing=true;
              }
            }
          }
 while (bKeepGoing);
        }
 else {
          for (; i < arg.length(); i++) {
            c=arg.charAt(i);
            if (Util.isIdentifier(c))             sbv.append(c);
 else {
              i--;
              break;
            }
          }
        }
      }
      String var=sbv.toString();
      if (!Util.isBlank(var)) {
        XValue value=null;
        if (var.equals("String_Node_Str")) {
          result.add(mArgs);
        }
 else         value=extractSingle(var,cQuote != '\0');
        if (value != null)         result.append(value);
      }
    }
 else     result.append(c);
  }
  result.flush();
  if (!bExpandWild)   return result.getResult();
  ArrayList<XValue> result2=new ArrayList<XValue>();
  for (  XValue v : result.getResult()) {
    List<XValue> r=expandWild(v);
    if (r != null)     result2.addAll(r);
  }
  return result2;
}