Program: 42264
Project: 42264
Buggy source:
List<XValue> expandToList(String arg,EvalEnv env) 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(arg.substring(3,arg.length() - 3)));
    return r;
  }
  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;
  }
  Result result=new Result();
  char c;
  int i;
  CharAttr curAttr=env.preserveValue() ? CharAttr.ATTR_PRESERVE : CharAttr.ATTR_NONE;
  for (i=0; i < arg.length(); i++) {
    c=arg.charAt(i);
    if (env.parseQuotes()) {
      if (CharAttr.isQuote(c)) {
        CharAttr ca=CharAttr.valueOf(c);
        if (curAttr.isQuote()) {
          curAttr.clear(ca);
          if (curAttr.isQuote())           result.append(c,curAttr);
        }
 else {
          result.append((String)null,curAttr);
          curAttr.set(ca);
        }
        continue;
      }
 else       if (c == '\\') {
        if (curAttr.isHardQuote())         result.append(c,curAttr);
 else         if (i < arg.length()) {
          char nextc=arg.charAt(++i);
          if (curAttr.isSoftQuote()) {
switch (nextc) {
case '$':
case '`':
case '"':
case '\\':
case '\n':
              break;
default :
            result.append(c,curAttr);
          break;
      }
    }
    CharAttr cAttr=CharAttr.ATTR_ESCAPED;
    cAttr.set(curAttr);
    result.append(nextc,cAttr);
  }
  continue;
}
}
if (!curAttr.isHardQuote() && c == '$') {
if (++i == arg.length()) {
  result.append('$',curAttr);
  break;
}
StringBuffer sbv=new StringBuffer();
if (arg.charAt(i) == '{') {
  i=readToMatching(arg,i,sbv,'}');
}
 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)) {
  if (var.equals("String_Node_Str")) {
    boolean bFirst=true;
    for (    XValue v : mShell.getArgs()) {
      if (curAttr.isSoftQuote()) {
        if (!bFirst)         result.append(mIFS.getFirstChar(),curAttr);
        result.append(v,curAttr);
      }
 else {
        result.flush();
        result.add(v);
      }
      bFirst=false;
    }
  }
 else   if (var.equals("String_Node_Str")) {
    boolean bFirst=true;
    List<XValue> args=mShell.getArgs();
    if (args.isEmpty())     result.resetIfEmpty();
 else     for (    XValue v : args) {
      if (curAttr.isSoftQuote() && bFirst)       result.append(v,curAttr);
 else       result.add(v);
      bFirst=false;
    }
  }
 else {
    List<XValue> vs=evalVar(var,curAttr);
    if (vs != null) {
      int vsize=vs.size();
      for (int vi=0; vi < vsize; vi++) {
        XValue v=vs.get(vi);
        if (vi > 0)         result.flush();
        result.append(v,curAttr);
      }
    }
  }
}
 else result.append('$',curAttr);
}
 else {
result.append(c,curAttr);
}
}
result.flush();
ArrayList<XValue> result2=new ArrayList<XValue>();
for (Result.RXValue rv : result.getResult()) {
if (!env.expandWild()) result2.add(rv.toXValue());
 else {
if (rv.bRaw) result2.add(rv.xvalue);
 else {
  List<XValue> r=expandWild(rv);
  if (r != null)   result2.addAll(r);
}
}
}
return result2;
}

Fixed version (ground truth):
List<XValue> expandToList(String arg,EvalEnv env) 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(arg.substring(3,arg.length() - 3)));
    return r;
  }
  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;
  }
  Result result=new Result();
  char c;
  int i;
  CharAttr curAttr=env.preserveValue() ? CharAttr.ATTR_PRESERVE : CharAttr.ATTR_NONE;
  for (i=0; i < arg.length(); i++) {
    c=arg.charAt(i);
    if (env.parseQuotes()) {
      if (CharAttr.isQuote(c)) {
        CharAttr ca=CharAttr.valueOf(c);
        if (curAttr.isQuote()) {
          curAttr.clear(ca);
          if (curAttr.isQuote())           result.append(c,curAttr);
        }
 else {
          result.append((String)null,curAttr);
          curAttr.set(ca);
        }
        continue;
      }
 else       if (c == '\\') {
        if (curAttr.isHardQuote())         result.append(c,curAttr);
 else         if (i < arg.length()) {
          char nextc=arg.charAt(++i);
          if (curAttr.isSoftQuote()) {
switch (nextc) {
case '$':
case '`':
case '"':
case '\\':
case '\n':
              break;
default :
            result.append(c,curAttr);
          break;
      }
    }
    CharAttr cAttr=CharAttr.ATTR_ESCAPED;
    cAttr.set(curAttr);
    result.append(nextc,cAttr);
  }
  continue;
}
}
if (!curAttr.isHardQuote() && c == '$') {
if (++i == arg.length()) {
  result.append('$',curAttr);
  break;
}
StringBuffer sbv=new StringBuffer();
if (arg.charAt(i) == '{') {
  i=readToMatching(arg,i,sbv,'}');
}
 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)) {
  if (var.equals("String_Node_Str")) {
    boolean bFirst=true;
    for (    XValue v : mShell.getArgs()) {
      if (curAttr.isSoftQuote()) {
        if (!bFirst)         result.append(mIFS.getFirstChar(),curAttr);
        result.append(v,env,curAttr);
      }
 else {
        result.flush();
        result.add(v);
      }
      bFirst=false;
    }
  }
 else   if (var.equals("String_Node_Str")) {
    boolean bFirst=true;
    List<XValue> args=mShell.getArgs();
    if (args.isEmpty())     result.resetIfEmpty();
 else     for (    XValue v : args) {
      if (curAttr.isSoftQuote() && bFirst)       result.append(v,env,curAttr);
 else       result.add(v);
      bFirst=false;
    }
  }
 else {
    List<XValue> vs=evalVar(var,curAttr);
    if (vs != null) {
      int vsize=vs.size();
      for (int vi=0; vi < vsize; vi++) {
        XValue v=vs.get(vi);
        if (vi > 0)         result.flush();
        result.append(v,env,curAttr);
      }
    }
  }
}
 else result.append('$',curAttr);
}
 else {
result.append(c,curAttr);
}
}
result.flush();
ArrayList<XValue> result2=new ArrayList<XValue>();
for (Result.RXValue rv : result.getResult()) {
if (!env.expandWild()) result2.add(rv.toXValue());
 else {
if (rv.bRaw) result2.add(rv.xvalue);
 else {
  List<XValue> r=expandWild(rv);
  if (r != null)   result2.addAll(r);
}
}
}
return result2;
}