Program: 33519
Project: 33519
Buggy source:
@Override protected int run(final CmdLineParser parser){
  final List<String> args=parser.getRemainingArgs();
  if (args.isEmpty()) {
    System.err.println("String_Node_Str");
    return 3;
  }
  if (args.size() == 1) {
    System.err.println("String_Node_Str");
    return 3;
  }
  final Path outPath=new Path(args.get(0));
  final List<String> ins=args.subList(1,args.size());
  final boolean verbose=parser.getBoolean(verboseOpt);
  final SAMFileReader.ValidationStringency stringency=Utils.toStringency(parser.getOptionValue(stringencyOpt),"String_Node_Str");
  if (stringency == null)   return 3;
  final Configuration conf=getConf();
  final List<Path> inputs=new ArrayList<Path>(ins.size());
  for (  final String in : ins) {
    try {
      final Path p=new Path(in);
      for (      final FileStatus fstat : p.getFileSystem(conf).globStatus(p))       inputs.add(fstat.getPath());
    }
 catch (    IOException e) {
      System.err.printf("String_Node_Str",in,e.getMessage());
    }
  }
  final Path input0=inputs.get(0);
  SAMFormat format=SAMFormat.inferFromFilePath(input0);
  if (format == null) {
    try {
      format=SAMFormat.inferFromData(input0.getFileSystem(conf).open(input0));
    }
 catch (    IOException e) {
      System.err.printf("String_Node_Str",input0,e.getMessage());
      return 4;
    }
    if (format == null) {
      System.err.printf("String_Node_Str",inputs.get(0));
      return 4;
    }
  }
  final SAMFileHeader header;
  try {
    final SAMFileReader r=new SAMFileReader(input0.getFileSystem(conf).open(input0));
    header=r.getFileHeader();
    r.close();
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",input0,e.getMessage());
    return 5;
  }
  final OutputStream out;
  try {
    out=outPath.getFileSystem(conf).create(outPath);
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",e.getMessage());
    return 6;
  }
  try {
    new SAMOutputPreparer().prepareForRecords(out,format,header);
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",e.getMessage());
    return 7;
  }
  int inIdx=1;
  try {
    for (    final Path inPath : inputs) {
      if (verbose) {
        System.out.printf("String_Node_Str",inIdx++,inputs.size());
      }
switch (format) {
case SAM:
{
          final InputStream in=inPath.getFileSystem(conf).open(inPath);
          new SAMFileReader(in).getFileHeader();
          IOUtils.copyBytes(in,out,conf,false);
          in.close();
          break;
        }
case BAM:
{
        final FSDataInputStream in=inPath.getFileSystem(conf).open(inPath);
        final ByteBuffer block=ByteBuffer.wrap(new byte[0xffff]).order(ByteOrder.LITTLE_ENDIAN);
        for (int read=0, prev; (prev=in.read(block.array(),read,block.capacity() - read)) < block.capacity(); ) {
          if (prev == -1)           break;
          read+=prev;
        }
        int blockLength=0;
        for (int xlen=(int)block.getShort(10) & 0xffff, i=12, end=i + xlen; i < end; ) {
          final int slen=(int)block.getShort(i + 2) & 0xffff;
          if (block.getShort(i) == 0x4342 && slen == 2) {
            blockLength=((int)block.getShort(i + 4) & 0xffff) + 1;
            break;
          }
          i+=4 + slen;
        }
        if (blockLength == 0)         throw new IOException("String_Node_Str" + inPath);
        if (verbose) {
          System.err.printf("String_Node_Str",blockLength);
        }
        final ByteArrayInputStream blockIn=new ByteArrayInputStream(block.array(),0,blockLength);
        final BlockCompressedInputStream bin=new BlockCompressedInputStream(blockIn);
        final ByteBuffer buf=ByteBuffer.wrap(new byte[8]).order(ByteOrder.LITTLE_ENDIAN);
        IOUtils.readFully(bin,buf.array(),0,8);
        final int magic=buf.getInt(0), headerLen=buf.getInt(4);
        if (magic != 0x014d4142)         throw new IOException("String_Node_Str" + inPath);
        IOUtils.skipFully(bin,headerLen);
        IOUtils.readFully(bin,buf.array(),0,4);
        for (int i=buf.getInt(0); i-- > 0; ) {
          IOUtils.readFully(bin,buf.array(),0,4);
          IOUtils.skipFully(bin,buf.getInt(0) + 4);
        }
        final int remaining=bin.available();
        if (verbose)         System.err.printf("String_Node_Str",remaining);
        if (remaining > 0) {
          final byte[] remBuf=new byte[remaining];
          IOUtils.readFully(bin,remBuf,0,remBuf.length);
          final BlockCompressedOutputStream bout=new BlockCompressedOutputStream(out,null);
          bout.write(remBuf);
          bout.flush();
        }
        in.seek(blockLength);
        IOUtils.copyBytes(in,out,conf,false);
        in.close();
        break;
      }
  }
}
}
 catch (IOException e) {
System.err.printf("String_Node_Str",e.getMessage());
return 8;
}
try {
if (format == SAMFormat.BAM) out.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK);
out.close();
}
 catch (IOException e) {
System.err.printf("String_Node_Str",e.getMessage());
return 9;
}
return 0;
}

Fixed version (ground truth):
@Override protected int run(final CmdLineParser parser){
  final List<String> args=parser.getRemainingArgs();
  if (args.isEmpty()) {
    System.err.println("String_Node_Str");
    return 3;
  }
  if (args.size() == 1) {
    System.err.println("String_Node_Str");
    return 3;
  }
  final Path outPath=new Path(args.get(0));
  final List<String> ins=args.subList(1,args.size());
  final boolean verbose=parser.getBoolean(verboseOpt);
  final SAMFileReader.ValidationStringency stringency=Utils.toStringency(parser.getOptionValue(stringencyOpt,SAMFileReader.ValidationStringency.DEFAULT_STRINGENCY.toString()),"String_Node_Str");
  if (stringency == null)   return 3;
  final Configuration conf=getConf();
  final List<Path> inputs=new ArrayList<Path>(ins.size());
  for (  final String in : ins) {
    try {
      final Path p=new Path(in);
      for (      final FileStatus fstat : p.getFileSystem(conf).globStatus(p))       inputs.add(fstat.getPath());
    }
 catch (    IOException e) {
      System.err.printf("String_Node_Str",in,e.getMessage());
    }
  }
  final Path input0=inputs.get(0);
  SAMFormat format=SAMFormat.inferFromFilePath(input0);
  if (format == null) {
    try {
      format=SAMFormat.inferFromData(input0.getFileSystem(conf).open(input0));
    }
 catch (    IOException e) {
      System.err.printf("String_Node_Str",input0,e.getMessage());
      return 4;
    }
    if (format == null) {
      System.err.printf("String_Node_Str",inputs.get(0));
      return 4;
    }
  }
  final SAMFileHeader header;
  try {
    final SAMFileReader r=new SAMFileReader(input0.getFileSystem(conf).open(input0));
    header=r.getFileHeader();
    r.close();
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",input0,e.getMessage());
    return 5;
  }
  final OutputStream out;
  try {
    out=outPath.getFileSystem(conf).create(outPath);
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",e.getMessage());
    return 6;
  }
  try {
    new SAMOutputPreparer().prepareForRecords(out,format,header);
  }
 catch (  IOException e) {
    System.err.printf("String_Node_Str",e.getMessage());
    return 7;
  }
  int inIdx=1;
  try {
    for (    final Path inPath : inputs) {
      if (verbose) {
        System.out.printf("String_Node_Str",inIdx++,inputs.size());
      }
switch (format) {
case SAM:
{
          final InputStream in=inPath.getFileSystem(conf).open(inPath);
          new SAMFileReader(in).getFileHeader();
          IOUtils.copyBytes(in,out,conf,false);
          in.close();
          break;
        }
case BAM:
{
        final FSDataInputStream in=inPath.getFileSystem(conf).open(inPath);
        final ByteBuffer block=ByteBuffer.wrap(new byte[0xffff]).order(ByteOrder.LITTLE_ENDIAN);
        for (int read=0, prev; (prev=in.read(block.array(),read,block.capacity() - read)) < block.capacity(); ) {
          if (prev == -1)           break;
          read+=prev;
        }
        int blockLength=0;
        for (int xlen=(int)block.getShort(10) & 0xffff, i=12, end=i + xlen; i < end; ) {
          final int slen=(int)block.getShort(i + 2) & 0xffff;
          if (block.getShort(i) == 0x4342 && slen == 2) {
            blockLength=((int)block.getShort(i + 4) & 0xffff) + 1;
            break;
          }
          i+=4 + slen;
        }
        if (blockLength == 0)         throw new IOException("String_Node_Str" + inPath);
        if (verbose) {
          System.err.printf("String_Node_Str",blockLength);
        }
        final ByteArrayInputStream blockIn=new ByteArrayInputStream(block.array(),0,blockLength);
        final BlockCompressedInputStream bin=new BlockCompressedInputStream(blockIn);
        final ByteBuffer buf=ByteBuffer.wrap(new byte[8]).order(ByteOrder.LITTLE_ENDIAN);
        IOUtils.readFully(bin,buf.array(),0,8);
        final int magic=buf.getInt(0), headerLen=buf.getInt(4);
        if (magic != 0x014d4142)         throw new IOException("String_Node_Str" + inPath);
        IOUtils.skipFully(bin,headerLen);
        IOUtils.readFully(bin,buf.array(),0,4);
        for (int i=buf.getInt(0); i-- > 0; ) {
          IOUtils.readFully(bin,buf.array(),0,4);
          IOUtils.skipFully(bin,buf.getInt(0) + 4);
        }
        final int remaining=bin.available();
        if (verbose)         System.err.printf("String_Node_Str",remaining);
        if (remaining > 0) {
          final byte[] remBuf=new byte[remaining];
          IOUtils.readFully(bin,remBuf,0,remBuf.length);
          final BlockCompressedOutputStream bout=new BlockCompressedOutputStream(out,null);
          bout.write(remBuf);
          bout.flush();
        }
        in.seek(blockLength);
        IOUtils.copyBytes(in,out,conf,false);
        in.close();
        break;
      }
  }
}
}
 catch (IOException e) {
System.err.printf("String_Node_Str",e.getMessage());
return 8;
}
try {
if (format == SAMFormat.BAM) out.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK);
out.close();
}
 catch (IOException e) {
System.err.printf("String_Node_Str",e.getMessage());
return 9;
}
return 0;
}