Program: 161273
Project: 161273
Buggy source:
@Override public int doWork(final List<String> args){
  if (this.bedFile == null || !this.bedFile.exists()) {
    LOG.error("String_Node_Str");
    return -1;
  }
  if (args.isEmpty()) {
    LOG.error("String_Node_Str");
    return -1;
  }
  if (this.minCoverages.isEmpty()) {
    this.minCoverages.add(0);
  }
  final String NO_PARTITION="String_Node_Str";
  BufferedReader bedIn=null;
  final List<SamReader> samReaders=new ArrayList<>(args.size());
  PrintWriter pw=null;
  ReferenceGenome referenceGenome=null;
  ReferenceContig referenceContig=null;
  try {
    final BedLineCodec codec=new BedLineCodec();
    final Set<String> all_partitions=new TreeSet<>();
    bedIn=IOUtils.openFileForBufferedReading(this.bedFile);
    SAMSequenceDictionary dict=null;
    for (    final String filename : IOUtils.unrollFiles(args)) {
      LOG.info(filename);
      final SamReader samReader=super.openSamReader(filename);
      if (!samReader.hasIndex()) {
        LOG.error(filename + "String_Node_Str");
        samReader.close();
        return -1;
      }
      final SAMFileHeader samFileheader=samReader.getFileHeader();
      if (samFileheader == null) {
        LOG.error("String_Node_Str" + filename);
        return -1;
      }
      final List<SAMReadGroupRecord> readGroups=samFileheader.getReadGroups();
      if (readGroups == null || readGroups.isEmpty()) {
        LOG.warn("String_Node_Str" + filename);
        all_partitions.add(NO_PARTITION);
      }
 else {
        for (        final SAMReadGroupRecord rg : readGroups) {
          all_partitions.add(this.partition.apply(rg,NO_PARTITION));
        }
      }
      final SAMSequenceDictionary d=samFileheader.getSequenceDictionary();
      if (d == null) {
        samReader.close();
        LOG.error(JvarkitException.BamDictionaryMissing.getMessage(filename));
        return -1;
      }
      samReaders.add(samReader);
      if (dict == null) {
        dict=d;
      }
 else       if (SequenceUtil.areSequenceDictionariesEqual(d,dict)) {
        LOG.error(JvarkitException.DictionariesAreNotTheSame.getMessage(d,dict));
        return -1;
      }
    }
    if (samReaders.isEmpty()) {
      LOG.error("String_Node_Str");
      return -1;
    }
    if (!StringUtil.isBlank(this.faidxUri)) {
      referenceGenome=new ReferenceGenomeFactory().open(this.faidxUri);
    }
    pw=super.openFileOrStdoutAsPrintWriter(this.outputFile);
    pw.print("String_Node_Str" + this.partition.name() + (referenceGenome == null ? "String_Node_Str" : "String_Node_Str"));
    pw.print("String_Node_Str");
    for (    final int MIN_COVERAGE : this.minCoverages) {
      pw.print("String_Node_Str" + MIN_COVERAGE + "String_Node_Str"+ MIN_COVERAGE+ "String_Node_Str"+ MIN_COVERAGE+ "String_Node_Str"+ MIN_COVERAGE);
    }
    pw.println();
    String line=null;
    while ((line=bedIn.readLine()) != null) {
      if (line.isEmpty() || line.startsWith("String_Node_Str"))       continue;
      final BedLine bedLine=codec.decode(line);
      if (bedLine == null)       continue;
      if (dict.getSequence(bedLine.getContig()) == null) {
        LOG.error("String_Node_Str" + line);
        return -1;
      }
      if (bedLine.getStart() > bedLine.getEnd()) {
        LOG.info("String_Node_Str" + bedLine);
        continue;
      }
      if (referenceGenome != null && (referenceContig == null || !referenceContig.hasName(bedLine.getContig()))) {
        referenceContig=referenceGenome.getContig(bedLine.getContig());
      }
      final Map<String,IntervalStat> sample2stats=new HashMap<>(all_partitions.size());
      for (      final String rgId : all_partitions) {
        sample2stats.put(rgId,new IntervalStat(bedLine));
      }
      for (      final SamReader samReader : samReaders) {
        final SAMRecordIterator r=samReader.queryOverlapping(bedLine.getContig(),bedLine.getStart(),bedLine.getEnd());
        while (r.hasNext()) {
          final SAMRecord rec=r.next();
          if (rec.getReadUnmappedFlag())           continue;
          if (this.filter.filterOut(rec))           continue;
          if (!rec.getReferenceName().equals(bedLine.getContig()))           continue;
          final String partition;
          final SAMReadGroupRecord group=rec.getReadGroup();
          if (group == null) {
            partition=NO_PARTITION;
          }
 else {
            final String name=this.partition.apply(group);
            partition=(StringUtil.isBlank(name) ? NO_PARTITION : name);
          }
          IntervalStat stat=sample2stats.get(partition);
          if (stat == null) {
            stat=new IntervalStat(bedLine);
            sample2stats.put(partition,stat);
          }
          stat.visit(rec);
        }
        r.close();
      }
      final OptionalInt gcPercentInt=(referenceContig == null ? OptionalInt.empty() : referenceContig.getGCPercent(bedLine.getStart() - 1,bedLine.getEnd()).getGCPercentAsInteger());
      for (      final String partitionName : sample2stats.keySet()) {
        final IntervalStat stat=sample2stats.get(partitionName);
        Arrays.sort(stat.counts);
        pw.print(bedLine.getContig() + "String_Node_Str" + (bedLine.getStart() - 1)+ "String_Node_Str"+ (bedLine.getEnd())+ "String_Node_Str"+ stat.counts.length+ "String_Node_Str"+ partitionName);
        if (referenceGenome != null) {
          pw.print("String_Node_Str");
          if (gcPercentInt.isPresent())           pw.print(gcPercentInt.getAsInt());
        }
        pw.print("String_Node_Str" + stat.counts[0] + "String_Node_Str"+ stat.counts[stat.counts.length - 1]);
        for (        final int MIN_COVERAGE : this.minCoverages) {
          final IntUnaryOperator depthAdjuster=(D) -> (D <= MIN_COVERAGE ? 0 : D);
          final int count_no_coverage=(int)Arrays.stream(stat.counts).filter(D -> depthAdjuster.applyAsInt(D) <= 0).count();
          final double mean=Percentile.average().evaluate(Arrays.stream(stat.counts).map(depthAdjuster));
          final double median_depth=Percentile.median().evaluate(Arrays.stream(stat.counts).map(depthAdjuster));
          pw.print("String_Node_Str" + mean + "String_Node_Str"+ median_depth+ "String_Node_Str"+ count_no_coverage+ "String_Node_Str"+ (int)(((stat.counts.length - count_no_coverage) / (double)stat.counts.length) * 100.0));
        }
        pw.println();
      }
    }
    pw.flush();
    pw.close();
    pw=null;
    LOG.info("String_Node_Str");
    return RETURN_OK;
  }
 catch (  final Exception err) {
    LOG.error(err);
    return -1;
  }
 finally {
    CloserUtil.close(referenceGenome);
    CloserUtil.close(pw);
    CloserUtil.close(bedIn);
    CloserUtil.close(samReaders);
  }
}

Fixed version (ground truth):
@Override public int doWork(final List<String> args){
  if (this.bedFile == null || !this.bedFile.exists()) {
    LOG.error("String_Node_Str");
    return -1;
  }
  if (args.isEmpty()) {
    LOG.error("String_Node_Str");
    return -1;
  }
  if (this.minCoverages.isEmpty()) {
    this.minCoverages.add(0);
  }
  final String NO_PARTITION="String_Node_Str";
  BufferedReader bedIn=null;
  final List<SamReader> samReaders=new ArrayList<>(args.size());
  PrintWriter pw=null;
  ReferenceGenome referenceGenome=null;
  ReferenceContig referenceContig=null;
  try {
    final BedLineCodec codec=new BedLineCodec();
    final Set<String> all_partitions=new TreeSet<>();
    bedIn=IOUtils.openFileForBufferedReading(this.bedFile);
    SAMSequenceDictionary dict=null;
    for (    final String filename : IOUtils.unrollFiles(args)) {
      LOG.info(filename);
      final SamReader samReader=super.openSamReader(filename);
      if (!samReader.hasIndex()) {
        LOG.error(filename + "String_Node_Str");
        samReader.close();
        return -1;
      }
      final SAMFileHeader samFileheader=samReader.getFileHeader();
      if (samFileheader == null) {
        LOG.error("String_Node_Str" + filename);
        return -1;
      }
      final List<SAMReadGroupRecord> readGroups=samFileheader.getReadGroups();
      if (readGroups == null || readGroups.isEmpty()) {
        LOG.warn("String_Node_Str" + filename);
        all_partitions.add(NO_PARTITION);
      }
 else {
        for (        final SAMReadGroupRecord rg : readGroups) {
          all_partitions.add(this.partition.apply(rg,NO_PARTITION));
        }
      }
      final SAMSequenceDictionary d=samFileheader.getSequenceDictionary();
      if (d == null) {
        samReader.close();
        LOG.error(JvarkitException.BamDictionaryMissing.getMessage(filename));
        return -1;
      }
      samReaders.add(samReader);
      if (dict == null) {
        dict=d;
      }
 else       if (!SequenceUtil.areSequenceDictionariesEqual(d,dict)) {
        LOG.error(JvarkitException.DictionariesAreNotTheSame.getMessage(d,dict));
        return -1;
      }
    }
    if (samReaders.isEmpty()) {
      LOG.error("String_Node_Str");
      return -1;
    }
    if (!StringUtil.isBlank(this.faidxUri)) {
      referenceGenome=new ReferenceGenomeFactory().open(this.faidxUri);
    }
    pw=super.openFileOrStdoutAsPrintWriter(this.outputFile);
    pw.print("String_Node_Str" + this.partition.name() + (referenceGenome == null ? "String_Node_Str" : "String_Node_Str"));
    pw.print("String_Node_Str");
    for (    final int MIN_COVERAGE : this.minCoverages) {
      pw.print("String_Node_Str" + MIN_COVERAGE + "String_Node_Str"+ MIN_COVERAGE+ "String_Node_Str"+ MIN_COVERAGE+ "String_Node_Str"+ MIN_COVERAGE);
    }
    pw.println();
    String line=null;
    while ((line=bedIn.readLine()) != null) {
      if (line.isEmpty() || line.startsWith("String_Node_Str"))       continue;
      final BedLine bedLine=codec.decode(line);
      if (bedLine == null)       continue;
      if (dict.getSequence(bedLine.getContig()) == null) {
        LOG.error("String_Node_Str" + line);
        return -1;
      }
      if (bedLine.getStart() > bedLine.getEnd()) {
        LOG.info("String_Node_Str" + bedLine);
        continue;
      }
      if (referenceGenome != null && (referenceContig == null || !referenceContig.hasName(bedLine.getContig()))) {
        referenceContig=referenceGenome.getContig(bedLine.getContig());
      }
      final Map<String,IntervalStat> sample2stats=new HashMap<>(all_partitions.size());
      for (      final String rgId : all_partitions) {
        sample2stats.put(rgId,new IntervalStat(bedLine));
      }
      for (      final SamReader samReader : samReaders) {
        final SAMRecordIterator r=samReader.queryOverlapping(bedLine.getContig(),bedLine.getStart(),bedLine.getEnd());
        while (r.hasNext()) {
          final SAMRecord rec=r.next();
          if (rec.getReadUnmappedFlag())           continue;
          if (this.filter.filterOut(rec))           continue;
          if (!rec.getReferenceName().equals(bedLine.getContig()))           continue;
          final String partition;
          final SAMReadGroupRecord group=rec.getReadGroup();
          if (group == null) {
            partition=NO_PARTITION;
          }
 else {
            final String name=this.partition.apply(group);
            partition=(StringUtil.isBlank(name) ? NO_PARTITION : name);
          }
          IntervalStat stat=sample2stats.get(partition);
          if (stat == null) {
            stat=new IntervalStat(bedLine);
            sample2stats.put(partition,stat);
          }
          stat.visit(rec);
        }
        r.close();
      }
      final OptionalInt gcPercentInt=(referenceContig == null ? OptionalInt.empty() : referenceContig.getGCPercent(bedLine.getStart() - 1,bedLine.getEnd()).getGCPercentAsInteger());
      for (      final String partitionName : sample2stats.keySet()) {
        final IntervalStat stat=sample2stats.get(partitionName);
        Arrays.sort(stat.counts);
        pw.print(bedLine.getContig() + "String_Node_Str" + (bedLine.getStart() - 1)+ "String_Node_Str"+ (bedLine.getEnd())+ "String_Node_Str"+ stat.counts.length+ "String_Node_Str"+ partitionName);
        if (referenceGenome != null) {
          pw.print("String_Node_Str");
          if (gcPercentInt.isPresent())           pw.print(gcPercentInt.getAsInt());
        }
        pw.print("String_Node_Str" + stat.counts[0] + "String_Node_Str"+ stat.counts[stat.counts.length - 1]);
        for (        final int MIN_COVERAGE : this.minCoverages) {
          final IntUnaryOperator depthAdjuster=(D) -> (D <= MIN_COVERAGE ? 0 : D);
          final int count_no_coverage=(int)Arrays.stream(stat.counts).filter(D -> depthAdjuster.applyAsInt(D) <= 0).count();
          final double mean=Percentile.average().evaluate(Arrays.stream(stat.counts).map(depthAdjuster));
          final double median_depth=Percentile.median().evaluate(Arrays.stream(stat.counts).map(depthAdjuster));
          pw.print("String_Node_Str" + mean + "String_Node_Str"+ median_depth+ "String_Node_Str"+ count_no_coverage+ "String_Node_Str"+ (int)(((stat.counts.length - count_no_coverage) / (double)stat.counts.length) * 100.0));
        }
        pw.println();
      }
    }
    pw.flush();
    pw.close();
    pw=null;
    LOG.info("String_Node_Str");
    return RETURN_OK;
  }
 catch (  final Exception err) {
    LOG.error(err);
    return -1;
  }
 finally {
    CloserUtil.close(referenceGenome);
    CloserUtil.close(pw);
    CloserUtil.close(bedIn);
    CloserUtil.close(samReaders);
  }
}