nus-yam/ex-repair huggingface dataset:
Program: 42299
Project: 42299
Buggy source:
public int run(List<XValue> args) throws Exception {
  for (  XValue arg : args)   mShell.getEnv().unsetVar(arg.toString());
  InputPort stdin=mShell.getEnv().getStdin();
  InputStream is=stdin.asInputStream(getSerializeOpts());
  String line=Util.readLine(is);
  if (line == null)   return 1;
  String ifs=getIFSRegex();
  String[] results=line.split(ifs,args.size());
  for (int i=0; i < args.size(); i++)   if (i < results.length)   mShell.getEnv().setVar(args.get(i).toString(),new XValue(results[i]),false);
  is.close();
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  for (  XValue arg : args)   mShell.getEnv().unsetVar(arg.toString());
  InputPort stdin=mShell.getEnv().getStdin();
  InputStream is=stdin.asInputStream(getSerializeOpts());
  String line=Util.readLine(is,getSerializeOpts().getText_encoding());
  if (line == null)   return 1;
  String ifs=getIFSRegex();
  String[] results=line.split(ifs,args.size());
  for (int i=0; i < args.size(); i++)   if (i < results.length)   mShell.getEnv().setVar(args.get(i).toString(),new XValue(results[i]),false);
  is.close();
  return 0;
}
Program: 42300
Project: 42300
Buggy source:
public int run(List<XValue> args) throws Exception {
  mFormatter=new CSVFormatter();
  mOutput=getStdout().asOutputStream();
  Options opts=new Options("String_Node_Str");
  opts.parse(args);
  bHeader=opts.hasOpt("String_Node_Str");
  bAttr=opts.hasOpt("String_Node_Str");
  Processor processor=Shell.getProcessor();
  mCompiler=processor.newXQueryCompiler();
  XdmNode context=null;
  DocumentBuilder builder=processor.newDocumentBuilder();
  if (!opts.hasOpt("String_Node_Str")) {
    OptionValue ov=opts.getOpt("String_Node_Str");
    if (ov != null && ov.getValue().isXExpr()) {
      XdmItem item=ov.getValue().asXdmValue().itemAt(0);
      if (item instanceof XdmNode)       context=builder.build(((XdmNode)item).asSource());
    }
    if (context == null) {
      if (ov != null && !ov.getValue().toString().equals("String_Node_Str"))       context=builder.build(getSource(ov.getValue()));
 else {
        context=getStdin().asXdmNode(getSerializeOpts());
      }
    }
  }
  if (bAttr) {
    mFieldXPath="String_Node_Str";
    mHeaderXPath="String_Node_Str";
  }
  XQueryExecutable expr=mCompiler.compile(mRowXpath);
  XQueryEvaluator eval=expr.load();
  if (context != null)   eval.setContextItem(context);
  boolean bFirst=true;
  for (  XdmItem row : eval) {
    if (bFirst && bHeader) {
      writeHeader(row);
      bFirst=false;
    }
    writeLine(row,mFieldXPath);
  }
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  mFormatter=new CSVFormatter();
  Options opts=new Options("String_Node_Str");
  opts.parse(args);
  mOutput=getStdout().asOutputStream(getSerializeOpts());
  bHeader=opts.hasOpt("String_Node_Str");
  bAttr=opts.hasOpt("String_Node_Str");
  Processor processor=Shell.getProcessor();
  mCompiler=processor.newXQueryCompiler();
  XdmNode context=null;
  DocumentBuilder builder=processor.newDocumentBuilder();
  if (!opts.hasOpt("String_Node_Str")) {
    OptionValue ov=opts.getOpt("String_Node_Str");
    if (ov != null && ov.getValue().isXExpr()) {
      XdmItem item=ov.getValue().asXdmValue().itemAt(0);
      if (item instanceof XdmNode)       context=builder.build(((XdmNode)item).asSource());
    }
    if (context == null) {
      if (ov != null && !ov.getValue().toString().equals("String_Node_Str"))       context=builder.build(getSource(ov.getValue()));
 else {
        context=getStdin().asXdmNode(getSerializeOpts());
      }
    }
  }
  if (bAttr) {
    mFieldXPath="String_Node_Str";
    mHeaderXPath="String_Node_Str";
  }
  XQueryExecutable expr=mCompiler.compile(mRowXpath);
  XQueryEvaluator eval=expr.load();
  if (context != null)   eval.setContextItem(context);
  boolean bFirst=true;
  for (  XdmItem row : eval) {
    if (bFirst && bHeader) {
      writeHeader(row);
      bFirst=false;
    }
    writeLine(row,mFieldXPath);
  }
  return 0;
}
Program: 42302
Project: 42302
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  String getVar=opts.getOptString("String_Node_Str",null);
  String setVar=opts.getOptString("String_Node_Str",null);
  Boolean noErr=opts.hasOpt("String_Node_Str");
  if (getVar == null && setVar == null) {
    usage();
    return 1;
  }
  ManagedHttpSession msess=(ManagedHttpSession)getShell().getSession().getVar("String_Node_Str");
  if (msess == null) {
    printErr("String_Node_Str");
    return 2;
  }
  try {
    SerializeOpts serializeOpts=getSerializeOpts(opts);
    if (getVar != null) {
      Object value=msess.getSession().getAttribute(getVar);
      if (value != null) {
        writeValue(value,serializeOpts);
        return 0;
      }
 else       if (!noErr)       printErr("String_Node_Str" + getVar);
      return 1;
    }
 else     if (setVar != null) {
      args=opts.getRemainingArgs();
      if (args.size() < 1) {
        usage();
        return 1;
      }
      msess.getSession().setAttribute(setVar,args.get(0));
      return 0;
    }
  }
  finally {
    msess.release();
  }
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  String getVar=opts.getOptString("String_Node_Str",null);
  String setVar=opts.getOptString("String_Node_Str",null);
  Boolean noErr=opts.hasOpt("String_Node_Str");
  if (getVar == null && setVar == null) {
    usage();
    return 1;
  }
  ManagedHttpSession msess=(ManagedHttpSession)getShell().getSession().getVar("String_Node_Str");
  if (msess == null) {
    printErr("String_Node_Str");
    return 2;
  }
  try {
    if (getVar != null) {
      Object value=msess.getSession().getAttribute(getVar);
      if (value != null) {
        writeValue(value,serializeOpts);
        return 0;
      }
 else       if (!noErr)       printErr("String_Node_Str" + getVar);
      return 1;
    }
 else     if (setVar != null) {
      args=opts.getRemainingArgs();
      if (args.size() < 1) {
        usage();
        return 1;
      }
      msess.getSession().setAttribute(setVar,args.get(0));
      return 0;
    }
  }
  finally {
    msess.release();
  }
  return 0;
}
Program: 42303
Project: 42303
Buggy source:
private void writeValue(Object value,SerializeOpts serializeOpts) throws CoreException, IOException {
  if (value instanceof XValue) {
    XValue xv=(XValue)value;
    IXdmValueOutputStream dest=getStdout().asXdmValueOutputStream(serializeOpts);
    dest.write(xv.asXdmValue());
  }
 else {
    String svalue=value.toString();
    getStdout().asPrintStream().print(svalue);
  }
}

Fixed version (ground truth):
private void writeValue(Object value,SerializeOpts serializeOpts) throws CoreException, IOException {
  if (value instanceof XValue) {
    XValue xv=(XValue)value;
    IXdmValueOutputStream dest=getStdout().asXdmValueOutputStream(serializeOpts);
    dest.write(xv.asXdmValue());
  }
 else {
    String svalue=value.toString();
    getStdout().asPrintStream(serializeOpts).print(svalue);
  }
}
Program: 42305
Project: 42305
Buggy source:
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  bHeader=opts.hasOpt("String_Node_Str");
  bAttr=opts.hasOpt("String_Node_Str");
  String delim=opts.getOptString("String_Node_Str","String_Node_Str");
  String quote=opts.getOptString("String_Node_Str","String_Node_Str");
  mFormatter=new CSVFormatter(delim.charAt(0),quote.charAt(0));
  mOutput=getStdout().asOutputStream();
  Processor processor=Shell.getProcessor();
  mCompiler=processor.newXQueryCompiler();
  InputPort in=getStdin();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XdmNode context=in.asXdmNode(serializeOpts);
  if (bAttr) {
    mFieldXPath="String_Node_Str";
    mHeaderXPath="String_Node_Str";
  }
  XQueryExecutable expr=mCompiler.compile(mRowXpath);
  XQueryEvaluator eval=expr.load();
  if (context != null)   eval.setContextItem(context);
  boolean bFirst=true;
  for (  XdmItem row : eval) {
    if (bFirst && bHeader) {
      writeHeader(row);
      bFirst=false;
    }
    writeLine(row,mFieldXPath);
  }
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  bHeader=opts.hasOpt("String_Node_Str");
  bAttr=opts.hasOpt("String_Node_Str");
  String delim=opts.getOptString("String_Node_Str","String_Node_Str");
  String quote=opts.getOptString("String_Node_Str","String_Node_Str");
  mFormatter=new CSVFormatter(delim.charAt(0),quote.charAt(0));
  mOutput=getStdout().asOutputStream(serializeOpts);
  Processor processor=Shell.getProcessor();
  mCompiler=processor.newXQueryCompiler();
  InputPort in=getStdin();
  XdmNode context=in.asXdmNode(serializeOpts);
  if (bAttr) {
    mFieldXPath="String_Node_Str";
    mHeaderXPath="String_Node_Str";
  }
  XQueryExecutable expr=mCompiler.compile(mRowXpath);
  XQueryEvaluator eval=expr.load();
  if (context != null)   eval.setContextItem(context);
  boolean bFirst=true;
  for (  XdmItem row : eval) {
    if (bFirst && bHeader) {
      writeHeader(row);
      bFirst=false;
    }
    writeLine(row,mFieldXPath);
  }
  return 0;
}
Program: 42306
Project: 42306
Buggy source:
private void writeText(Properties props,String comment) throws IOException {
  props.store(getEnv().getStdout().asOutputStream(),comment);
}

Fixed version (ground truth):
private void writeText(Properties props,String comment,SerializeOpts serializeOpts) throws IOException {
  props.store(getEnv().getStdout().asOutputStream(serializeOpts),comment);
}
Program: 42307
Project: 42307
Buggy source:
private void writeVars(Properties props,List<String> vars) throws UnsupportedEncodingException, IOException, InvalidArgumentException {
  PrintWriter out=getStdout().asPrintWriter(getSerializeOpts());
  for (  String var : vars)   out.println(props.getProperty(var,"String_Node_Str"));
  out.flush();
}

Fixed version (ground truth):
private void writeVars(Properties props,List<String> vars,SerializeOpts serializeOpts) throws UnsupportedEncodingException, IOException, InvalidArgumentException {
  PrintWriter out=getStdout().asPrintWriter(serializeOpts);
  for (  String var : vars)   out.println(props.getProperty(var,"String_Node_Str"));
  out.flush();
}
Program: 42308
Project: 42308
Buggy source:
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  XValue optIn=opts.getOptValue("String_Node_Str");
  XValue optInXml=opts.getOptValue("String_Node_Str");
  boolean bOutText=opts.hasOpt("String_Node_Str");
  if (optIn != null && optInXml != null) {
    usage("String_Node_Str");
    return -1;
  }
  String comment=opts.getOptString("String_Node_Str",null);
  Properties props=new Properties();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  if (optInXml != null)   props.loadFromXML(getInput(optInXml).asInputStream(serializeOpts));
 else   if (optIn != null)   props.load(getInput(optIn).asInputStream(serializeOpts));
  if (opts.hasOpt("String_Node_Str"))   for (  XValue d : opts.getOpt("String_Node_Str").getValues())   props.remove(d.toString());
  List<String> printVars=null;
  if (opts.hasOpt("String_Node_Str")) {
    printVars=new ArrayList<String>();
    for (    XValue var : opts.getOpt("String_Node_Str").getValues())     printVars.add(var.toString());
  }
  if (opts.hasOpt("String_Node_Str")) {
    for (    XValue add : opts.getOpt("String_Node_Str").getValues()) {
      StringPair pair=new StringPair(add.toString(),'=');
      props.setProperty(pair.getLeft(),pair.getRight());
    }
  }
  if (printVars != null)   writeVars(props,printVars);
 else   if (!bOutText)   writeXML(props,comment);
 else   writeText(props,comment);
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XValue optIn=opts.getOptValue("String_Node_Str");
  XValue optInXml=opts.getOptValue("String_Node_Str");
  boolean bOutText=opts.hasOpt("String_Node_Str");
  if (optIn != null && optInXml != null) {
    usage("String_Node_Str");
    return -1;
  }
  String comment=opts.getOptString("String_Node_Str",null);
  Properties props=new Properties();
  if (optInXml != null)   props.loadFromXML(getInput(optInXml).asInputStream(serializeOpts));
 else   if (optIn != null)   props.load(getInput(optIn).asInputStream(serializeOpts));
  if (opts.hasOpt("String_Node_Str"))   for (  XValue d : opts.getOpt("String_Node_Str").getValues())   props.remove(d.toString());
  List<String> printVars=null;
  if (opts.hasOpt("String_Node_Str")) {
    printVars=new ArrayList<String>();
    for (    XValue var : opts.getOpt("String_Node_Str").getValues())     printVars.add(var.toString());
  }
  if (opts.hasOpt("String_Node_Str")) {
    for (    XValue add : opts.getOpt("String_Node_Str").getValues()) {
      StringPair pair=new StringPair(add.toString(),'=');
      props.setProperty(pair.getLeft(),pair.getRight());
    }
  }
  if (printVars != null)   writeVars(props,printVars,serializeOpts);
 else   if (!bOutText)   writeXML(props,comment);
 else   writeText(props,comment,serializeOpts);
  return 0;
}
Program: 42309
Project: 42309
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  String style=opts.getOptStringRequired("String_Node_Str");
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  Source source=getStdin().asSource(serializeOpts);
  apply(style,source,getStdout().asOutputStream(),opts.hasOpt("String_Node_Str") ? args : null,serializeOpts);
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  String style=opts.getOptStringRequired("String_Node_Str");
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  Source source=getStdin().asSource(serializeOpts);
  apply(style,source,getStdout().asOutputStream(serializeOpts),opts.hasOpt("String_Node_Str") ? args : null,serializeOpts);
  return 0;
}
Program: 42310
Project: 42310
Buggy source:
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  XValue zipfile=opts.getOptValue("String_Node_Str");
  args=opts.getRemainingArgs();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  ZipOutputStream zos=new ZipOutputStream(zipfile == null ? getStdout().asOutputStream() : this.getOutputStream(zipfile.toString(),false));
  try {
    int ret=0;
    ret=zip(zos,args);
    zos.finish();
  }
  finally {
    zos.close();
  }
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  XValue zipfile=opts.getOptValue("String_Node_Str");
  args=opts.getRemainingArgs();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  ZipOutputStream zos=new ZipOutputStream(zipfile == null ? getStdout().asOutputStream(serializeOpts) : this.getOutputStream(zipfile.toString(),false));
  try {
    int ret=0;
    ret=zip(zos,args);
    zos.finish();
  }
  finally {
    zos.close();
  }
  return 0;
}
Program: 42311
Project: 42311
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  boolean bDecode=opts.hasOpt("String_Node_Str");
  boolean bWrap=opts.hasOpt("String_Node_Str");
  InputPort iport=(args.isEmpty() ? getStdin() : getInput(args.get(0)));
  InputStream is=iport.asInputStream(getSerializeOpts(opts));
  OutputStream os=getStdout().asOutputStream();
  is=new BufferedInputStream(is);
  os=new BufferedOutputStream(os);
  try {
    if (bDecode)     decode(is,os);
 else     encode(is,os,bWrap);
  }
  finally {
    is.close();
    os.close();
    iport.release();
  }
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  boolean bDecode=opts.hasOpt("String_Node_Str");
  boolean bWrap=opts.hasOpt("String_Node_Str");
  InputPort iport=(args.isEmpty() ? getStdin() : getInput(args.get(0)));
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  InputStream is=iport.asInputStream(serializeOpts);
  OutputStream os=getStdout().asOutputStream(serializeOpts);
  is=new BufferedInputStream(is);
  os=new BufferedOutputStream(os);
  try {
    if (bDecode)     decode(is,os);
 else     encode(is,os,bWrap);
  }
  finally {
    is.close();
    os.close();
    iport.release();
  }
  return 0;
}
Program: 42312
Project: 42312
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  OutputStream stdout=getStdout().asOutputStream();
  if (args.size() > 0) {
    for (    XValue arg : args) {
      File inf=getFile(arg);
      if (!inf.exists()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      if (!inf.canRead()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      InputStream in=new FileInputStream(inf);
      Util.copyStream(in,stdout);
      in.close();
    }
  }
 else   Util.copyStream(getStdin().asInputStream(getSerializeOpts()),stdout);
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  OutputStream stdout=getStdout().asOutputStream(getSerializeOpts());
  if (args.size() > 0) {
    for (    XValue arg : args) {
      File inf=getFile(arg);
      if (!inf.exists()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      if (!inf.canRead()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      InputStream in=new FileInputStream(inf);
      Util.copyStream(in,stdout);
      in.close();
    }
  }
 else   Util.copyStream(getStdin().asInputStream(getSerializeOpts()),stdout);
  return 0;
}
Program: 42313
Project: 42313
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  mSerial=this.getSerializeOpts(opts);
  XValue vlines=getEnv().getVarValue("String_Node_Str");
  if (vlines != null)   mLines=(int)vlines.toLong();
  mLines=opts.getOptInt("String_Node_Str",mLines);
  OutputStream stdout=getStdout().asOutputStream();
  if (args.size() > 0) {
    for (    XValue arg : args) {
      File inf=getFile(arg);
      if (!inf.exists()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      if (!inf.canRead()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      InputStream in=new FileInputStream(inf);
      boolean bQuit=page(in,stdout);
      in.close();
      if (bQuit)       break;
    }
  }
 else   page(getStdin().asInputStream(getSerializeOpts()),stdout);
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str",SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  mSerial=this.getSerializeOpts(opts);
  XValue vlines=getEnv().getVarValue("String_Node_Str");
  if (vlines != null)   mLines=(int)vlines.toLong();
  mLines=opts.getOptInt("String_Node_Str",mLines);
  OutputStream stdout=getStdout().asOutputStream(mSerial);
  if (args.size() > 0) {
    for (    XValue arg : args) {
      File inf=getFile(arg);
      if (!inf.exists()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      if (!inf.canRead()) {
        this.printErr("String_Node_Str" + arg.toString());
        continue;
      }
      InputStream in=new FileInputStream(inf);
      boolean bQuit=page(in,stdout);
      in.close();
      if (bQuit)       break;
    }
  }
 else {
    page(getStdin().asInputStream(mSerial),stdout);
  }
  return 0;
}
Program: 42314
Project: 42314
Buggy source:
private boolean page(InputStream in,OutputStream stdout) throws IOException {
  Console con=System.console();
  if (con == null) {
    Util.copyStream(in,stdout);
    return false;
  }
  Reader r=con.reader();
  int lines=mLines;
  do {
    for (int i=0; i < lines; i++) {
      String l=Util.readLine(in);
      if (l == null)       return false;
      stdout.write(l.getBytes(mSerial.getText_encoding()));
      stdout.write('\n');
    }
    char[] ret=con.readPassword("String_Node_Str");
    if (ret == null)     return false;
    if (ret.length == 0)     continue;
    if (ret[0] == 'q' || ret[0] == 'Q')     return true;
  }
 while (true);
}

Fixed version (ground truth):
private boolean page(InputStream in,OutputStream stdout) throws IOException {
  Console con=System.console();
  if (con == null) {
    Util.copyStream(in,stdout);
    return false;
  }
  Reader r=con.reader();
  int lines=mLines;
  do {
    for (int i=0; i < lines; i++) {
      String l=Util.readLine(in,mSerial.getText_encoding());
      if (l == null)       return false;
      stdout.write(l.getBytes(mSerial.getText_encoding()));
      stdout.write('\n');
    }
    char[] ret=con.readPassword("String_Node_Str");
    if (ret == null)     return false;
    if (ret.length == 0)     continue;
    if (ret[0] == 'q' || ret[0] == 'Q')     return true;
  }
 while (true);
}
Program: 42315
Project: 42315
Buggy source:
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  File curdir=shell.getCurdir();
  mLogger.debug("String_Node_Str" + mCommandFile.getPath() + "String_Node_Str"+ curdir.getPath());
  ArrayList<XValue> cmdlist=new ArrayList<XValue>();
  cmdlist.add(new XValue(mCommandFile.getPath()));
  cmdlist.addAll(Util.expandSequences(args));
  Process proc=null;
synchronized (this.getClass()) {
    ProcessBuilder builder=new ProcessBuilder();
    builder.command(Util.toStringList(cmdlist));
    builder.directory(curdir);
    setEnvironment(shell,builder);
    proc=builder.start();
    if (proc == null)     return -1;
  }
  StreamCopier outCopier=new StreamCopier(proc.getInputStream(),shell.getEnv().getStdout().asOutputStream(),true);
  StreamCopier errCopier=new StreamCopier(proc.getErrorStream(),shell.getEnv().getStderr().asOutputStream(),true);
  PortCopier inCopier=null;
  if (shell.getEnv().isStdinRedirected())   inCopier=new PortCopier(shell.getEnv().getStdin(),proc.getOutputStream(),shell.getSerializeOpts(),true);
 else   proc.getOutputStream().close();
  errCopier.start();
  if (inCopier != null)   inCopier.start();
  outCopier.run();
  outCopier.closeIn();
  int ret=proc.waitFor();
  if (inCopier != null)   inCopier.join();
  outCopier.join();
  errCopier.join();
  return ret;
}

Fixed version (ground truth):
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  File curdir=shell.getCurdir();
  mLogger.debug("String_Node_Str" + mCommandFile.getPath() + "String_Node_Str"+ curdir.getPath());
  ArrayList<XValue> cmdlist=new ArrayList<XValue>();
  cmdlist.add(new XValue(mCommandFile.getPath()));
  cmdlist.addAll(Util.expandSequences(args));
  Process proc=null;
synchronized (this.getClass()) {
    ProcessBuilder builder=new ProcessBuilder();
    builder.command(Util.toStringList(cmdlist));
    builder.directory(curdir);
    setEnvironment(shell,builder);
    proc=builder.start();
    if (proc == null)     return -1;
  }
  StreamCopier outCopier=new StreamCopier(proc.getInputStream(),shell.getEnv().getStdout().asOutputStream(shell.getSerializeOpts()),true);
  StreamCopier errCopier=new StreamCopier(proc.getErrorStream(),shell.getEnv().getStderr().asOutputStream(shell.getSerializeOpts()),true);
  PortCopier inCopier=null;
  if (shell.getEnv().isStdinRedirected())   inCopier=new PortCopier(shell.getEnv().getStdin(),proc.getOutputStream(),shell.getSerializeOpts(),true);
 else   proc.getOutputStream().close();
  errCopier.start();
  if (inCopier != null)   inCopier.start();
  outCopier.run();
  outCopier.closeIn();
  int ret=proc.waitFor();
  if (inCopier != null)   inCopier.join();
  outCopier.join();
  errCopier.join();
  return ret;
}
Program: 42316
Project: 42316
Buggy source:
public synchronized PrintStream asPrintStream(){
  return new PrintStream(asOutputStream());
}

Fixed version (ground truth):
public synchronized PrintStream asPrintStream(SerializeOpts opts){
  return new PrintStream(asOutputStream(opts));
}
Program: 42317
Project: 42317
Buggy source:
public abstract OutputStream asOutputStream();

Fixed version (ground truth):
public abstract OutputStream asOutputStream(SerializeOpts opts);
Program: 42318
Project: 42318
Buggy source:
public synchronized PrintWriter asPrintWriter(SerializeOpts opts) throws UnsupportedEncodingException {
  return new PrintWriter(new OutputStreamWriter(asOutputStream(),opts.getText_encoding()));
}

Fixed version (ground truth):
public synchronized PrintWriter asPrintWriter(SerializeOpts opts) throws UnsupportedEncodingException {
  return new PrintWriter(new OutputStreamWriter(asOutputStream(opts),opts.getText_encoding()));
}
Program: 42320
Project: 42320
Buggy source:
private XValue removeQuotes(XValue v){
  if (v.isXExpr())   return v;
  String vs=v.toString();
  int vslen=vs.length();
  StringBuffer sb=new StringBuffer();
  char cQuote=0;
  for (int i=0; i < vslen; i++) {
    char c=vs.charAt(i);
    if (c == '\\' && i < vslen) {
      sb.append(c);
      c=vs.charAt(++i);
      sb.append(c);
      continue;
    }
    if (c == '"' || c == '\'') {
      if (c == cQuote) {
        cQuote=0;
        continue;
      }
 else       if (cQuote == 0) {
        cQuote=c;
        continue;
      }
    }
    sb.append(c);
  }
  String sbs=sb.toString();
  if (vs.equals(sbs))   return v;
 else   return new XValue(sbs);
}

Fixed version (ground truth):
private XValue removeQuotes(XValue v){
  if (v.isXExpr())   return v;
  String vs=v.toString();
  int vslen=vs.length();
  StringBuffer sb=new StringBuffer();
  char cQuote=0;
  for (int i=0; i < vslen; i++) {
    char c=vs.charAt(i);
    if (c == '\\' && i < vslen - 1) {
      c=vs.charAt(++i);
      if (c != '"' && c != '\'')       sb.append('\\');
      sb.append(c);
      continue;
    }
    if (c == '"' || c == '\'') {
      if (c == cQuote) {
        cQuote=0;
        continue;
      }
 else       if (cQuote == 0) {
        cQuote=c;
        continue;
      }
    }
    sb.append(c);
  }
  String sbs=sb.toString();
  if (vs.equals(sbs))   return v;
 else   return new XValue(sbs);
}
Program: 42323
Project: 42323
Buggy source:
public void append(XValue value,boolean inQuotes){
  if (value.isAtomic()) {
    if (inQuotes || cur != null || sb.length() > 0) {
      String str=value.toString();
      if (!inQuotes && Util.isEmpty(str))       return;
      ajoin();
      sb.append(str);
    }
 else     cur=value;
  }
 else {
    if (inQuotes) {
      boolean bFirst=true;
      for (      XdmValue v : value.asXdmValue()) {
        if (!bFirst)         append(sSEPSPACE);
        append(v.toString());
        bFirst=false;
      }
    }
 else {
      flush();
      add(value);
    }
  }
}

Fixed version (ground truth):
public void append(XValue value,boolean inQuotes){
  if (value.isAtomic()) {
    if (inQuotes || cur != null || sb.length() > 0) {
      String str=value.toString();
      if (!inQuotes && Util.isEmpty(str))       return;
      ajoin();
      sb.append(str);
    }
 else     cur=value;
  }
 else {
    if (inQuotes) {
      boolean bFirst=true;
      for (      XdmValue v : value.asXdmValue()) {
        if (!bFirst)         append(sSEPSPACE);
        String sv=v.toString();
        append(escapeQuotes(sv));
        bFirst=false;
      }
    }
 else {
      flush();
      add(value);
    }
  }
}
Program: 42324
Project: 42324
Buggy source:
public int run(List<XValue> args) throws Exception {
  Options opts=new Options(SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  OutputPort stdout=getEnv().getStdout();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XMLStreamWriter writer=stdout.asXMLStreamWriter(serializeOpts);
  writer.writeStartDocument();
  writer.writeStartElement("String_Node_Str");
  writeNetwork(writer);
  writer.writeEndElement();
  writer.writeEndDocument();
  stdout.writeSequenceTerminator(serializeOpts);
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  Options opts=new Options(SerializeOpts.getOptionDefs());
  opts.parse(args);
  OutputPort stdout=getEnv().getStdout();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XMLStreamWriter writer=stdout.asXMLStreamWriter(serializeOpts);
  writer.writeStartDocument();
  writer.writeStartElement("String_Node_Str");
  writeNetwork(writer);
  writer.writeEndElement();
  writer.writeEndDocument();
  stdout.writeSequenceTerminator(serializeOpts);
  return 0;
}
Program: 42326
Project: 42326
Buggy source:
public int run(List<XValue> args) throws Exception {
  Options opts=new Options(SerializeOpts.getOptionDefs());
  opts.parse(args);
  args=opts.getRemainingArgs();
  XFile file=new XFile(getCurdir());
  OutputPort stdout=getStdout();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XMLStreamWriter writer=stdout.asXMLStreamWriter(serializeOpts);
  writer.writeStartDocument();
  file.serialize(writer,false,false);
  writer.writeEndDocument();
  stdout.writeSequenceTerminator(serializeOpts);
  return 0;
}

Fixed version (ground truth):
public int run(List<XValue> args) throws Exception {
  Options opts=new Options(SerializeOpts.getOptionDefs());
  opts.parse(args);
  XFile file=new XFile(getCurdir());
  OutputPort stdout=getStdout();
  SerializeOpts serializeOpts=getSerializeOpts(opts);
  XMLStreamWriter writer=stdout.asXMLStreamWriter(serializeOpts);
  writer.writeStartDocument();
  file.serialize(writer,false,false);
  writer.writeEndDocument();
  stdout.writeSequenceTerminator(serializeOpts);
  return 0;
}
Program: 42327
Project: 42327
Buggy source:
private boolean page(InputStream in,OutputStream stdout) throws IOException {
  Console con=System.console();
  if (con == null) {
    Util.copyStream(in,stdout);
    return false;
  }
  Reader r=con.reader();
  int lines=mLines;
  do {
    for (int i=0; i < lines; i++) {
      String l=Util.readLine(in,mSerial.getText_encoding());
      if (l == null)       return false;
      stdout.write(l.getBytes(mSerial.getText_encoding()));
      stdout.write('\n');
    }
    char[] ret=con.readPassword("String_Node_Str");
    if (ret == null)     return false;
    if (ret.length == 0)     continue;
    if (ret[0] == 'q' || ret[0] == 'Q')     return true;
  }
 while (true);
}

Fixed version (ground truth):
private boolean page(InputStream in,OutputStream stdout) throws IOException {
  Console con=System.console();
  if (con == null) {
    Util.copyStream(in,stdout);
    return false;
  }
  int lines=mLines;
  do {
    for (int i=0; i < lines; i++) {
      String l=Util.readLine(in,mSerial.getText_encoding());
      if (l == null)       return false;
      stdout.write(l.getBytes(mSerial.getText_encoding()));
      stdout.write('\n');
    }
    char[] ret=con.readPassword("String_Node_Str");
    if (ret == null)     return false;
    if (ret.length == 0)     continue;
    if (ret[0] == 'q' || ret[0] == 'Q')     return true;
  }
 while (true);
}
Program: 42328
Project: 42328
Buggy source:
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str");
  opts.parse(args);
  args=opts.getRemainingArgs();
  String sRefFile=opts.getOptString("String_Node_Str",null);
  File refFile=sRefFile == null ? null : getFile(sRefFile);
  long modtime=refFile != null ? refFile.lastModified() : (new Date()).getTime();
  for (  XValue arg : args) {
    File file=getFile(arg);
    file.createNewFile();
    if (refFile != null)     file.setLastModified(modtime);
 else     file.setLastModified(modtime);
  }
  return 0;
}

Fixed version (ground truth):
@Override public int run(List<XValue> args) throws Exception {
  Options opts=new Options("String_Node_Str");
  opts.parse(args);
  args=opts.getRemainingArgs();
  String sRefFile=opts.getOptString("String_Node_Str",null);
  File refFile=sRefFile == null ? null : getFile(sRefFile);
  long modtime=refFile != null ? refFile.lastModified() : (new Date()).getTime();
  for (  XValue arg : args) {
    File file=getFile(arg);
    file.createNewFile();
    file.setLastModified(modtime);
  }
  return 0;
}
Program: 42329
Project: 42329
Buggy source:
@Override public XMLStreamWriter asXMLStreamWriter(SerializeOpts opts){
  ReceivingContentHandler rch=new ReceivingContentHandler();
  Receiver r=null;
  Builder b=new TinyBuilder();
  PipelineConfiguration pipe=Shell.getProcessor().getUnderlyingConfiguration().makePipelineConfiguration();
  b.setPipelineConfiguration(pipe);
  r=b;
  rch.setReceiver(r);
  rch.setPipelineConfiguration(pipe);
  XMLStreamWriterToContentHandler sw=new XMLStreamWriterToContentHandler(rch);
  mBuilder=b;
  return sw;
}

Fixed version (ground truth):
@Override public synchronized XMLStreamWriter asXMLStreamWriter(SerializeOpts opts){
  ReceivingContentHandler rch=new ReceivingContentHandler();
  Receiver r=null;
  Builder b=new TinyBuilder();
  PipelineConfiguration pipe=Shell.getProcessor().getUnderlyingConfiguration().makePipelineConfiguration();
  b.setPipelineConfiguration(pipe);
  r=b;
  rch.setReceiver(r);
  rch.setPipelineConfiguration(pipe);
  XMLStreamWriterToContentHandler sw=new XMLStreamWriterToContentHandler(rch);
  mBuilder=b;
  return sw;
}
Program: 42330
Project: 42330
Buggy source:
public int run(List<XValue> args,XEnvironment env) throws Exception {
  mEnvironment=env;
  mShell=env.getShell();
  return run(args);
}

Fixed version (ground truth):
public URLClassLoader run(){
  return new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]));
}
Program: 42331
Project: 42331
Buggy source:
protected ClassLoader getClassLoader(XValue classpath) throws MalformedURLException, IOException, URISyntaxException {
  if (classpath == null)   return this.getClass().getClassLoader();
  List<URL> urls=new ArrayList<URL>();
  for (  XdmItem item : classpath.asXdmValue()) {
    String cp=item.getStringValue();
    URL url=getShell().getURL(cp);
    urls.add(url);
  }
  URLClassLoader loader=new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]));
  return loader;
}

Fixed version (ground truth):
protected ClassLoader getClassLoader(XValue classpath) throws MalformedURLException, IOException, URISyntaxException {
  if (classpath == null)   return this.getClass().getClassLoader();
  final List<URL> urls=new ArrayList<URL>();
  for (  XdmItem item : classpath.asXdmValue()) {
    String cp=item.getStringValue();
    URL url=getShell().getURL(cp);
    urls.add(url);
  }
  URLClassLoader loader=AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>(){
    public URLClassLoader run(){
      return new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]));
    }
  }
);
  return loader;
}
Program: 42332
Project: 42332
Buggy source:
public void printErr(String s,Exception e){
  PrintWriter out;
  try {
    out=getEnv().getStderr().asPrintWriter(getSerializeOpts());
  }
 catch (  IOException e1) {
    mLogger.error("String_Node_Str" + s,e);
    return;
  }
  out.println(s);
  out.println(e.getMessage());
  out.flush();
}

Fixed version (ground truth):
public void printErr(String s,Exception e){
  PrintWriter out;
  try {
    out=getEnv().getStderr().asPrintWriter(getSerializeOpts());
  }
 catch (  IOException e1) {
    mLogger.error("String_Node_Str" + s,e);
    return;
  }
  out.println(s);
  out.println(e.getMessage());
  out.flush();
  out.close();
}
Program: 42333
Project: 42333
Buggy source:
public void printOut(String s){
  PrintWriter out;
  try {
    out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(getEnv().getStdout().asOutputStream(getSerializeOpts()),getSerializeOpts().getText_encoding())));
  }
 catch (  IOException e) {
    mLogger.error("String_Node_Str" + s,e);
    return;
  }
  out.println(s);
  out.flush();
}

Fixed version (ground truth):
public void printOut(String s){
  PrintWriter out;
  try {
    out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(getEnv().getStdout().asOutputStream(getSerializeOpts()),getSerializeOpts().getText_encoding())));
  }
 catch (  IOException e) {
    mLogger.error("String_Node_Str" + s,e);
    return;
  }
  out.println(s);
  out.flush();
  out.close();
}
Program: 42335
Project: 42335
Buggy source:
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  File curdir=shell.getCurdir();
  mLogger.debug("String_Node_Str" + mCommandFile.getPath() + "String_Node_Str"+ curdir.getPath());
  ArrayList<XValue> cmdlist=new ArrayList<XValue>();
  cmdlist.add(new XValue(mCommandFile.getPath()));
  cmdlist.addAll(Util.expandSequences(args));
  Process proc=null;
synchronized (this.getClass()) {
    ProcessBuilder builder=new ProcessBuilder();
    builder.command(Util.toStringList(cmdlist));
    builder.directory(curdir);
    proc=builder.start();
    if (proc == null)     return -1;
  }
  StreamCopier outCopier=new StreamCopier(proc.getInputStream(),shell.getEnv().getStdout().asOutputStream(),true);
  StreamCopier errCopier=new StreamCopier(proc.getErrorStream(),shell.getEnv().getStderr().asOutputStream(),true);
  PortCopier inCopier=null;
  if (shell.getEnv().isStdinRedirected())   inCopier=new PortCopier(shell.getEnv().getStdin(),proc.getOutputStream(),shell.getSerializeOpts(),true);
 else   proc.getOutputStream().close();
  errCopier.start();
  if (inCopier != null)   inCopier.start();
  outCopier.run();
  int ret=proc.waitFor();
  if (inCopier != null)   inCopier.join();
  outCopier.join();
  errCopier.join();
  return ret;
}

Fixed version (ground truth):
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  File curdir=shell.getCurdir();
  mLogger.debug("String_Node_Str" + mCommandFile.getPath() + "String_Node_Str"+ curdir.getPath());
  ArrayList<XValue> cmdlist=new ArrayList<XValue>();
  cmdlist.add(new XValue(mCommandFile.getPath()));
  cmdlist.addAll(Util.expandSequences(args));
  Process proc=null;
synchronized (this.getClass()) {
    ProcessBuilder builder=new ProcessBuilder();
    builder.command(Util.toStringList(cmdlist));
    builder.directory(curdir);
    proc=builder.start();
    if (proc == null)     return -1;
  }
  StreamCopier outCopier=new StreamCopier(proc.getInputStream(),shell.getEnv().getStdout().asOutputStream(),true);
  StreamCopier errCopier=new StreamCopier(proc.getErrorStream(),shell.getEnv().getStderr().asOutputStream(),true);
  PortCopier inCopier=null;
  if (shell.getEnv().isStdinRedirected())   inCopier=new PortCopier(shell.getEnv().getStdin(),proc.getOutputStream(),shell.getSerializeOpts(),true);
 else   proc.getOutputStream().close();
  errCopier.start();
  if (inCopier != null)   inCopier.start();
  outCopier.run();
  outCopier.closeIn();
  int ret=proc.waitFor();
  if (inCopier != null)   inCopier.join();
  outCopier.join();
  errCopier.join();
  return ret;
}
Program: 42336
Project: 42336
Buggy source:
@Override public void run(){
  try {
    Util.copyStream(mIn,mOut);
  }
 catch (  IOException e) {
    mLogger.warn("String_Node_Str",e);
  }
 finally {
    if (mCloseOut)     try {
      mOut.close();
    }
 catch (    IOException e) {
      mLogger.warn("String_Node_Str",e);
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    Util.copyStream(mIn,mOut);
  }
 catch (  IOException e) {
    mLogger.warn("String_Node_Str",e);
  }
 finally {
    if (mCloseOut)     closeOut();
  }
}
Program: 42337
Project: 42337
Buggy source:
private CommandFactory(){
  addBuiltin("String_Node_Str",xcd.class);
  addBuiltin("String_Node_Str",xecho.class);
  addBuiltin("String_Node_Str",echo.class);
  addBuiltin("String_Node_Str",xfalse.class);
  addBuiltin("String_Node_Str",xtrue.class);
  addBuiltin("String_Node_Str",set.class);
  addBuiltin("String_Node_Str",source.class);
  addBuiltin("String_Node_Str",source.class);
  addBuiltin("String_Node_Str",exit.class);
  addBuiltin("String_Node_Str",colon.class);
  addBuiltin("String_Node_Str",test.class);
  addBuiltin("String_Node_Str",test.class);
  addBuiltin("String_Node_Str",shift.class);
  addBuiltin("String_Node_Str",read.class);
  addBuiltin("String_Node_Str",xread.class);
  addBuiltin("String_Node_Str",unset.class);
  addBuiltin("String_Node_Str",xwhich.class);
  addBuiltin("String_Node_Str",xversion.class);
  addBuiltin("String_Node_Str",jobs.class);
  addBuiltin("String_Node_Str",wait.class);
  addBuiltin("String_Node_Str",xbreak.class);
  addBuiltin("String_Node_Str",xcontinue.class);
  addBuiltin("String_Node_Str",eval.class);
  addBuiltin("String_Node_Str",declare.class);
  addBuiltin("String_Node_Str",xreturn.class);
  addBuiltin("String_Node_Str",ximport.class);
  addBuiltin("String_Node_Str",xmlsh.class);
  addBuiltin("String_Node_Str",xthrow.class);
  addBuiltin("String_Node_Str",tie.class);
  addBuiltin("String_Node_Str",log.class);
  addBuiltin("String_Node_Str",xtype.class);
  addBuiltin("String_Node_Str",require.class);
}

Fixed version (ground truth):
private CommandFactory(){
  addBuiltin("String_Node_Str",xcd.class);
  addBuiltin("String_Node_Str",xecho.class);
  addBuiltin("String_Node_Str",echo.class);
  addBuiltin("String_Node_Str",xfalse.class);
  addBuiltin("String_Node_Str",xtrue.class);
  addBuiltin("String_Node_Str",set.class);
  addBuiltin("String_Node_Str",source.class);
  addBuiltin("String_Node_Str",source.class);
  addBuiltin("String_Node_Str",exit.class);
  addBuiltin("String_Node_Str",colon.class);
  addBuiltin("String_Node_Str",test.class);
  addBuiltin("String_Node_Str",test.class);
  addBuiltin("String_Node_Str",shift.class);
  addBuiltin("String_Node_Str",read.class);
  addBuiltin("String_Node_Str",xread.class);
  addBuiltin("String_Node_Str",unset.class);
  addBuiltin("String_Node_Str",xwhich.class);
  addBuiltin("String_Node_Str",xversion.class);
  addBuiltin("String_Node_Str",jobs.class);
  addBuiltin("String_Node_Str",wait.class);
  addBuiltin("String_Node_Str",xbreak.class);
  addBuiltin("String_Node_Str",xcontinue.class);
  addBuiltin("String_Node_Str",eval.class);
  addBuiltin("String_Node_Str",declare.class);
  addBuiltin("String_Node_Str",xreturn.class);
  addBuiltin("String_Node_Str",ximport.class);
  addBuiltin("String_Node_Str",xmlsh.class);
  addBuiltin("String_Node_Str",xthrow.class);
  addBuiltin("String_Node_Str",tie.class);
  addBuiltin("String_Node_Str",log.class);
  addBuiltin("String_Node_Str",xtype.class);
  addBuiltin("String_Node_Str",require.class);
  addBuiltin("String_Node_Str",help.class);
}
Program: 42338
Project: 42338
Buggy source:
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  try {
    if (mSourceMode) {
      return shell.runScript(mScript);
    }
 else {
      Shell sh=shell.clone();
      try {
        if (args != null)         sh.setArgs(args);
        sh.setArg0(mScriptName);
        int ret=sh.runScript(mScript);
        return ret;
      }
  finally {
        sh.close();
      }
    }
  }
  finally {
    mScript.close();
  }
}

Fixed version (ground truth):
public int run(Shell shell,String cmd,List<XValue> args) throws Exception {
  try {
    if (mSourceMode) {
      return shell.runScript(mScript);
    }
 else {
      Shell sh=shell.clone();
      try {
        if (args != null)         sh.setArgs(args);
        sh.setArg0(mScriptName);
        int ret=sh.runScript(mScript);
        return ret;
      }
  finally {
        sh.close();
      }
    }
  }
  finally {
    close();
  }
}
Program: 42339
Project: 42339
Buggy source:
@Override public int exec(Shell shell) throws Exception {
  if (mCommand == null || mCommand.isEmpty())   return execNull(shell);
  List<XValue> cmdLine=mSuffix.toCmdLine(shell,mCommand);
  String cmdName=cmdLine.remove(0).toString();
  ICommand cmd=CommandFactory.getInstance().getCommand(shell,cmdName);
  if (cmd == null) {
    shell.printErr(mCommand + "String_Node_Str");
    return 1;
  }
  XIOEnvironment saved_io=null;
  Shell saved_shell=null;
  Module saved_module=null;
  if (mPrefix == null)   saved_io=shell.getEnv().saveIO();
 else {
    saved_shell=shell;
    shell=shell.clone();
  }
  saved_module=shell.getModule();
  Shell saved_context_shell=ShellContext.set(shell);
  try {
    if (mPrefix != null)     mPrefix.exec(shell);
    mSuffix.exec(shell);
    Module module=cmd.getModule();
    if (module != null)     shell.setModule(module);
    return cmd.run(shell,cmdName,cmdLine);
  }
 catch (  ThrowException e) {
    throw e;
  }
catch (  Exception e) {
    shell.printErr("String_Node_Str" + cmdName + "String_Node_Str"+ e.toString());
    mLogger.error("String_Node_Str" + cmdName,e);
    return -1;
  }
 finally {
    ShellContext.set(saved_context_shell);
    if (saved_io != null)     shell.getEnv().restoreIO(saved_io);
 else     if (saved_shell != null)     shell.close();
    shell.setModule(saved_module);
  }
}

Fixed version (ground truth):
@Override public int exec(Shell shell) throws Exception {
  if (mCommand == null || mCommand.isEmpty())   return execNull(shell);
  List<XValue> cmdLine=mSuffix.toCmdLine(shell,mCommand);
  String cmdName=cmdLine.remove(0).toString();
  ICommand cmd=CommandFactory.getInstance().getCommand(shell,cmdName);
  if (cmd == null) {
    shell.printErr(mCommand + "String_Node_Str");
    return 1;
  }
  XIOEnvironment saved_io=null;
  Shell saved_shell=null;
  Module saved_module=null;
  if (mPrefix == null)   saved_io=shell.getEnv().saveIO();
 else {
    saved_shell=shell;
    shell=shell.clone();
  }
  saved_module=shell.getModule();
  Shell saved_context_shell=ShellContext.set(shell);
  try {
    if (mPrefix != null)     mPrefix.exec(shell);
    mSuffix.exec(shell);
    Module module=cmd.getModule();
    if (module != null)     shell.setModule(module);
    return cmd.run(shell,cmdName,cmdLine);
  }
 catch (  ThrowException e) {
    cmd.close();
    throw e;
  }
catch (  Exception e) {
    shell.printErr("String_Node_Str" + cmdName + "String_Node_Str"+ e.toString());
    mLogger.error("String_Node_Str" + cmdName,e);
    return -1;
  }
 finally {
    ShellContext.set(saved_context_shell);
    if (saved_io != null)     shell.getEnv().restoreIO(saved_io);
 else     if (saved_shell != null)     shell.close();
    shell.setModule(saved_module);
  }
}