nus-yam/ex-repair huggingface dataset:
Program: 30440
Project: 30440
Buggy source:
private static Index createIndex(final File inputFile,final FeatureIterator iterator,final IndexCreator creator){
  Feature lastFeature=null;
  Feature currentFeature;
  final Map<String,Feature> visitedChromos=new HashMap<String,Feature>(40);
  while (iterator.hasNext()) {
    final long position=iterator.getPosition();
    currentFeature=iterator.next();
    checkSorted(inputFile,lastFeature,currentFeature);
    final String curChr=currentFeature.getContig();
    final String lastChr=lastFeature != null ? lastFeature.getContig() : null;
    if (!curChr.equals(lastChr)) {
      if (visitedChromos.containsKey(curChr)) {
        String msg="String_Node_Str";
        msg+="String_Node_Str" + featToString(visitedChromos.get(curChr));
        msg+="String_Node_Str" + featToString(lastFeature);
        msg+="String_Node_Str" + featToString(currentFeature);
        throw new TribbleException.MalformedFeatureFile(msg,inputFile.getAbsolutePath());
      }
 else {
        visitedChromos.put(curChr,currentFeature);
      }
    }
    creator.addFeature(currentFeature,position);
    lastFeature=currentFeature;
  }
  iterator.close();
  return creator.finalizeIndex(iterator.getPosition());
}

Fixed version (ground truth):
private static Index createIndex(final File inputFile,final FeatureIterator iterator,final IndexCreator creator){
  Feature lastFeature=null;
  Feature currentFeature;
  final Map<String,Feature> visitedChromos=new HashMap<String,Feature>(40);
  while (iterator.hasNext()) {
    final long position=iterator.getPosition();
    currentFeature=iterator.next();
    checkSorted(inputFile,lastFeature,currentFeature);
    final String curChr=currentFeature.getContig();
    final String lastChr=lastFeature != null ? lastFeature.getContig() : null;
    if (!curChr.equals(lastChr)) {
      if (visitedChromos.containsKey(curChr)) {
        String msg="String_Node_Str";
        msg+="String_Node_Str" + featToString(visitedChromos.get(curChr));
        msg+="String_Node_Str" + featToString(lastFeature);
        msg+="String_Node_Str" + featToString(currentFeature);
        throw new TribbleException.MalformedFeatureFile(msg,inputFile.getAbsolutePath());
      }
 else {
        visitedChromos.put(curChr,currentFeature);
      }
    }
    creator.addFeature(currentFeature,position);
    lastFeature=currentFeature;
  }
  long finalPosition=iterator.getPosition();
  iterator.close();
  return creator.finalizeIndex(finalPosition);
}
Program: 30441
Project: 30441
Buggy source:
/** 
 * Get reference sequence without validating name or length.  This is OK if the entire sequence dictionary was validated before reading sequences.
 */
public ReferenceSequence get(final int sequenceIndex){
  if (referenceSequence != null && referenceSequence.getContigIndex() == sequenceIndex) {
    return referenceSequence;
  }
  if (referenceSequence != null && referenceSequence.getContigIndex() > sequenceIndex) {
    throw new SAMException("String_Node_Str" + sequenceIndex + "String_Node_Str"+ referenceSequence.getContigIndex());
  }
  referenceSequence=null;
  if (referenceSequenceFile.isIndexed()) {
    final SAMSequenceRecord samSequenceRecord=referenceSequenceFile.getSequenceDictionary().getSequence(sequenceIndex);
    if (samSequenceRecord != null) {
      referenceSequence=referenceSequenceFile.getSequence(samSequenceRecord.getSequenceName());
    }
  }
 else {
    do {
      referenceSequence=referenceSequenceFile.nextSequence();
    }
 while (referenceSequence != null && referenceSequence.getContigIndex() < sequenceIndex);
  }
  if (referenceSequence == null || referenceSequence.getContigIndex() != sequenceIndex) {
    throw new SAMException("String_Node_Str" + sequenceIndex + "String_Node_Str"+ referenceSequenceFile.toString());
  }
  return referenceSequence;
}

Fixed version (ground truth):
/** 
 * Get reference sequence without validating name or length.  This is OK if the entire sequence dictionary was validated before reading sequences.
 */
public ReferenceSequence get(final int sequenceIndex){
  if (referenceSequence != null && referenceSequence.getContigIndex() == sequenceIndex) {
    return referenceSequence;
  }
  if (referenceSequence != null && referenceSequence.getContigIndex() > sequenceIndex) {
    throw new SAMException("String_Node_Str" + sequenceIndex + "String_Node_Str"+ referenceSequence.getContigIndex());
  }
  referenceSequence=null;
  if (referenceSequenceFile.isIndexed() && referenceSequenceFile.getSequenceDictionary() != null) {
    final SAMSequenceRecord samSequenceRecord=referenceSequenceFile.getSequenceDictionary().getSequence(sequenceIndex);
    if (samSequenceRecord != null) {
      referenceSequence=referenceSequenceFile.getSequence(samSequenceRecord.getSequenceName());
    }
  }
 else {
    do {
      referenceSequence=referenceSequenceFile.nextSequence();
    }
 while (referenceSequence != null && referenceSequence.getContigIndex() < sequenceIndex);
  }
  if (referenceSequence == null || referenceSequence.getContigIndex() != sequenceIndex) {
    throw new SAMException("String_Node_Str" + sequenceIndex + "String_Node_Str"+ referenceSequenceFile.toString());
  }
  return referenceSequence;
}
Program: 30442
Project: 30442
Buggy source:
@Override public SAMRecordIterator assertSorted(final SortOrder sortOrder){
  return null;
}

Fixed version (ground truth):
@Override public SAMRecordIterator assertSorted(final SortOrder sortOrder){
  return this;
}
Program: 30443
Project: 30443
Buggy source:
@Override public SAMRecordIterator assertSorted(final SortOrder sortOrder){
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
@Override public SAMRecordIterator assertSorted(final SortOrder sortOrder){
  return SamReader.AssertingIterator.of(this).assertSorted(sortOrder);
}
Program: 30444
Project: 30444
Buggy source:
/** 
 * Merges a sorted collection of intervals and optionally concatenates unique names or takes the first name. 
 */
static Interval merge(final SortedSet<Interval> intervals,final boolean concatenateNames){
  final String chrom=intervals.first().getContig();
  int start=intervals.first().getStart();
  int end=intervals.last().getEnd();
  final boolean neg=intervals.first().isNegativeStrand();
  final LinkedHashSet<String> names=new LinkedHashSet<String>();
  final String name;
  for (  final Interval i : intervals) {
    if (i.getName() != null)     names.add(i.getName());
    start=Math.min(start,i.getStart());
    end=Math.max(end,i.getEnd());
  }
  if (concatenateNames) {
    if (names.isEmpty())     name=null;
 else     name=StringUtil.join("String_Node_Str",names);
  }
 else {
    name=names.iterator().next();
  }
  return new Interval(chrom,start,end,neg,name);
}

Fixed version (ground truth):
/** 
 * Merges a sorted collection of intervals and optionally concatenates unique names or takes the first name. 
 */
static Interval merge(final SortedSet<Interval> intervals,final boolean concatenateNames){
  final String chrom=intervals.first().getContig();
  int start=intervals.first().getStart();
  int end=intervals.last().getEnd();
  final boolean neg=intervals.first().isNegativeStrand();
  final LinkedHashSet<String> names=new LinkedHashSet<String>();
  final String name;
  for (  final Interval i : intervals) {
    if (i.getName() != null)     names.add(i.getName());
    start=Math.min(start,i.getStart());
    end=Math.max(end,i.getEnd());
  }
  if (names.isEmpty())   name=null;
 else   if (concatenateNames)   name=StringUtil.join("String_Node_Str",names);
 else   name=names.iterator().next();
  return new Interval(chrom,start,end,neg,name);
}
Program: 30445
Project: 30445
Buggy source:
public boolean isAdjacent(final Node<V1> interval){
  return mStart == interval.getEnd() || mEnd == interval.getStart();
}

Fixed version (ground truth):
public boolean isAdjacent(final Node<V1> interval){
  return mStart == interval.getEnd() + 1 || mEnd + 1 == interval.getStart();
}
Program: 30446
Project: 30446
Buggy source:
public int getLength(){
  return mEnd - mStart;
}

Fixed version (ground truth):
public int getLength(){
  return mEnd - mStart + 1;
}
Program: 30447
Project: 30447
Buggy source:
public int getRelationship(final Node<V1> interval){
  int result=0;
  if (mStart < interval.getStart())   result=HAS_LESSER_PART;
  if (mEnd > interval.getEnd())   result|=HAS_GREATER_PART;
  if (mStart < interval.getEnd() && interval.getStart() < mEnd)   result|=HAS_OVERLAPPING_PART;
  return result;
}

Fixed version (ground truth):
public int getRelationship(final Node<V1> interval){
  int result=0;
  if (mStart < interval.getStart())   result=HAS_LESSER_PART;
  if (mEnd > interval.getEnd())   result|=HAS_GREATER_PART;
  if (mStart <= interval.getEnd() && interval.getStart() <= mEnd)   result|=HAS_OVERLAPPING_PART;
  return result;
}
Program: 30448
Project: 30448
Buggy source:
/** 
 * Reverses the quals in place. 
 */
public static void reverseQualities(final byte[] quals){
  final int lastIndex=quals.length - 1;
  int i, j;
  for (i=0, j=lastIndex; i < j; ++i, --j) {
    final byte tmp=quals[i];
    quals[i]=quals[j];
    quals[j]=tmp;
  }
}

Fixed version (ground truth):
/** 
 * Reverses the quals in place. 
 */
public static void reverseQualities(final byte[] quals){
  reverse(quals,0,quals.length);
}
Program: 30450
Project: 30450
Buggy source:
/** 
 * Reads text SAM header and converts to a SAMFileHeader object.
 * @param reader Where to get header text from.
 * @param source Name of the input file, for error messages.  May be null.
 * @return complete header object.
 */
public SAMFileHeader decode(final LineReader reader,final String source){
  mFileHeader=new SAMFileHeader();
  mReader=reader;
  mSource=source;
  sequences=new ArrayList<SAMSequenceRecord>();
  readGroups=new ArrayList<SAMReadGroupRecord>();
  while (advanceLine() != null) {
    final ParsedHeaderLine parsedHeaderLine=new ParsedHeaderLine(mCurrentLine);
    if (!parsedHeaderLine.isLineValid()) {
      continue;
    }
switch (parsedHeaderLine.getHeaderRecordType()) {
case HD:
      parseHDLine(parsedHeaderLine);
    break;
case PG:
  parsePGLine(parsedHeaderLine);
break;
case RG:
parseRGLine(parsedHeaderLine);
break;
case SQ:
parseSQLine(parsedHeaderLine);
break;
case CO:
mFileHeader.addComment(mCurrentLine);
break;
default :
throw new IllegalStateException("String_Node_Str" + parsedHeaderLine.getHeaderRecordType());
}
}
mFileHeader.setSequenceDictionary(new SAMSequenceDictionary(sequences));
mFileHeader.setReadGroups(readGroups);
if (!mFileHeader.getValidationErrors().isEmpty() || textHeader.length() < (1024 * 1024)) {
mFileHeader.setTextHeader(textHeader.toString());
}
SAMUtils.processValidationErrors(mFileHeader.getValidationErrors(),-1,validationStringency);
return mFileHeader;
}

Fixed version (ground truth):
/** 
 * Reads text SAM header and converts to a SAMFileHeader object.
 * @param reader Where to get header text from.
 * @param source Name of the input file, for error messages.  May be null.
 * @return complete header object.
 */
public SAMFileHeader decode(final LineReader reader,final String source){
  mFileHeader=new SAMFileHeader();
  mReader=reader;
  mSource=source;
  sequences=new ArrayList<>();
  readGroups=new ArrayList<>();
  while (advanceLine() != null) {
    final ParsedHeaderLine parsedHeaderLine=new ParsedHeaderLine(mCurrentLine);
    if (!parsedHeaderLine.isLineValid()) {
      continue;
    }
switch (parsedHeaderLine.getHeaderRecordType()) {
case HD:
      parseHDLine(parsedHeaderLine);
    break;
case PG:
  parsePGLine(parsedHeaderLine);
break;
case RG:
parseRGLine(parsedHeaderLine);
break;
case SQ:
parseSQLine(parsedHeaderLine);
break;
case CO:
mFileHeader.addComment(mCurrentLine);
break;
default :
throw new IllegalStateException("String_Node_Str" + parsedHeaderLine.getHeaderRecordType());
}
}
mFileHeader.setSequenceDictionary(new SAMSequenceDictionary(sequences));
mFileHeader.setReadGroups(readGroups);
if (!mFileHeader.getValidationErrors().isEmpty() || textHeader.length() < (1024 * 1024)) {
mFileHeader.setTextHeader(textHeader.toString());
}
SAMUtils.processValidationErrors(mFileHeader.getValidationErrors(),-1,validationStringency);
return mFileHeader;
}
Program: 30451
Project: 30451
Buggy source:
/** 
 * Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.
 * @param cramFile        CRAM stream to read. May not be null.
 * @param indexFile       index file to be used for random access. May be null.
 * @param referenceSource a {@link htsjdk.samtools.cram.ref.CRAMReferenceSource source} ofreference sequences. May not be null.
 * @param validationStringency Validation stringency to be used when reading
 * @throws IllegalArgumentException if the {@code cramFile} or the {@code CRAMReferenceSource} is null
 */
public CRAMFileReader(final File cramFile,final File indexFile,final CRAMReferenceSource referenceSource,final ValidationStringency validationStringency) throws IOException {
  this(new FileInputStream(cramFile),indexFile,referenceSource,validationStringency);
  this.cramFile=cramFile;
}

Fixed version (ground truth):
/** 
 * Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.
 * @param cramFile        CRAM stream to read. May not be null.
 * @param indexFile       index file to be used for random access. May be null.
 * @param referenceSource a {@link htsjdk.samtools.cram.ref.CRAMReferenceSource source} ofreference sequences. May not be null.
 * @param validationStringency Validation stringency to be used when reading
 * @throws IllegalArgumentException if the {@code cramFile} or the {@code CRAMReferenceSource} is null
 */
public CRAMFileReader(final File cramFile,final File indexFile,final CRAMReferenceSource referenceSource,final ValidationStringency validationStringency) throws IOException {
  if (cramFile == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (referenceSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.cramFile=cramFile;
  this.referenceSource=referenceSource;
  this.mIndexFile=findIndexForFile(indexFile,cramFile);
  final SeekableFileStream indexStream=this.mIndexFile == null ? null : new SeekableFileStream(this.mIndexFile);
  initWithStreams(new FileInputStream(cramFile),indexStream,validationStringency);
}
Program: 30452
Project: 30452
Buggy source:
private ReferenceSource createReferenceSource(){
  byte[] refBases=new byte[10 * 10];
  Arrays.fill(refBases,(byte)'A');
  InMemoryReferenceSequenceFile rsf=new InMemoryReferenceSequenceFile();
  rsf.add("String_Node_Str",refBases);
  return new ReferenceSource(rsf);
}

Fixed version (ground truth):
private static ReferenceSource createReferenceSource(){
  byte[] refBases=new byte[10 * 10];
  Arrays.fill(refBases,(byte)'A');
  InMemoryReferenceSequenceFile rsf=new InMemoryReferenceSequenceFile();
  rsf.add("String_Node_Str",refBases);
  return new ReferenceSource(rsf);
}
Program: 30453
Project: 30453
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader6_InputRequired() throws IOException {
  InputStream bis=null;
  File file=null;
  ReferenceSource refSource=null;
  new CRAMFileReader(bis,file,createReferenceSource(),ValidationStringency.STRICT);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader6_InputRequired() throws IOException {
  InputStream bis=null;
  File file=null;
  new CRAMFileReader(bis,file,createReferenceSource(),ValidationStringency.STRICT);
}
Program: 30454
Project: 30454
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader7_ReferenceRequired() throws IOException {
  InputStream bis=new ByteArrayInputStream(new byte[0]);
  File file=new File(TEST_DATA_DIR,"String_Node_Str");
  ReferenceSource refSource=null;
  new CRAMFileReader(file,file,refSource,ValidationStringency.STRICT);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader7_ReferenceRequired() throws IOException {
  ReferenceSource refSource=null;
  new CRAMFileReader(CRAM_WITH_CRAI,CRAM_WITH_CRAI,refSource,ValidationStringency.STRICT);
}
Program: 30455
Project: 30455
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader3_RequiredReference(){
  File inputFile=new File(TEST_DATA_DIR,"String_Node_Str");
  File indexFile=null;
  ReferenceSource refSource=null;
  new CRAMFileReader(inputFile,indexFile,refSource);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader3_RequiredReference(){
  File indexFile=null;
  ReferenceSource refSource=null;
  new CRAMFileReader(CRAM_WITH_CRAI,indexFile,refSource);
}
Program: 30456
Project: 30456
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader4_ReferenceRequired(){
  File inputFile=new File(TEST_DATA_DIR,"String_Node_Str");
  ReferenceSource refSource=null;
  new CRAMFileReader(inputFile,refSource);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader4_ReferenceRequired(){
  ReferenceSource refSource=null;
  new CRAMFileReader(CRAM_WITH_CRAI,refSource);
}
Program: 30457
Project: 30457
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalStateException.class) public void testCRAMReader1_ReferenceRequired(){
  File file=new File(TEST_DATA_DIR,"String_Node_Str");
  InputStream bis=null;
  new CRAMFileReader(file,bis);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalStateException.class) public void testCRAMReader1_ReferenceRequired(){
  InputStream bis=null;
  new CRAMFileReader(CRAM_WITH_CRAI,bis);
}
Program: 30458
Project: 30458
Buggy source:
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader2ReferenceRequired(){
  File file=new File(TEST_DATA_DIR,"String_Node_Str");
  InputStream bis=null;
  new CRAMFileReader(file,bis,null);
}

Fixed version (ground truth):
@Test(description="String_Node_Str",expectedExceptions=IllegalArgumentException.class) public void testCRAMReader2ReferenceRequired(){
  InputStream bis=null;
  new CRAMFileReader(CRAM_WITH_CRAI,bis,null);
}
Program: 30459
Project: 30459
Buggy source:
/** 
 * Checks to see if an exception has been raised in the writer thread and if so rethrows it as an Error or RuntimeException as appropriate.
 */
private final void checkAndRethrow(){
  final Throwable t=this.ex.get();
  if (t != null) {
    if (t instanceof Error)     throw (Error)t;
    if (t instanceof RuntimeException)     throw (RuntimeException)t;
 else     throw new RuntimeException(t);
  }
}

Fixed version (ground truth):
/** 
 * Checks to see if an exception has been raised in the writer thread and if so rethrows it as an Error or RuntimeException as appropriate.
 */
private final void checkAndRethrow(){
  final Throwable t=this.ex.getAndSet(null);
  if (t != null) {
    this.isClosed.set(true);
    if (t instanceof Error)     throw (Error)t;
    if (t instanceof RuntimeException)     throw (RuntimeException)t;
 else     throw new RuntimeException(t);
  }
}
Program: 30460
Project: 30460
Buggy source:
/** 
 * Create a CRAMContainerStreamWriter for writing SAM records into a series of CRAM containers on output stream, with an optional index.
 * @param outputStream where to write the CRAM stream.
 * @param indexStream where to write the output index. Can be null if no index is required.
 * @param source reference source
 * @param samFileHeader {@link SAMFileHeader} to be used. Sort order is determined by the sortOrder property of this arg.
 * @param cramId used for display in error message display
 */
public CRAMContainerStreamWriter(final OutputStream outputStream,final OutputStream indexStream,final ReferenceSource source,final SAMFileHeader samFileHeader,final String cramId){
  this.outputStream=outputStream;
  this.samFileHeader=samFileHeader;
  this.cramID=cramId;
  this.source=source;
  containerFactory=new ContainerFactory(samFileHeader,recordsPerSlice);
  if (indexStream != null) {
    indexer=new CRAMBAIIndexer(indexStream,samFileHeader);
  }
}

Fixed version (ground truth):
/** 
 * Create a CRAMContainerStreamWriter for writing SAM records into a series of CRAM containers on output stream, with an optional index.
 * @param outputStream where to write the CRAM stream.
 * @param indexStream where to write the output index. Can be null if no index is required.
 * @param source reference source
 * @param samFileHeader {@link SAMFileHeader} to be used. Sort order is determined by the sortOrder property of this arg.
 * @param cramId used for display in error message display
 */
public CRAMContainerStreamWriter(final OutputStream outputStream,final OutputStream indexStream,final CRAMReferenceSource source,final SAMFileHeader samFileHeader,final String cramId){
  this.outputStream=outputStream;
  this.samFileHeader=samFileHeader;
  this.cramID=cramId;
  this.source=source;
  containerFactory=new ContainerFactory(samFileHeader,recordsPerSlice);
  if (indexStream != null) {
    indexer=new CRAMBAIIndexer(indexStream,samFileHeader);
  }
}
Program: 30461
Project: 30461
Buggy source:
/** 
 * Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.
 * @param cramFile        CRAM stream to read. May not be null.
 * @param indexFile       index file to be used for random access. May be null.
 * @param referenceSource a {@link htsjdk.samtools.cram.ref.ReferenceSource source} ofreference sequences. May not be null.
 * @param validationStringency Validation stringency to be used when reading
 * @throws IllegalArgumentException if the {@code cramFile} or the {@code ReferenceSource} is null
 */
public CRAMFileReader(final File cramFile,final File indexFile,final ReferenceSource referenceSource,final ValidationStringency validationStringency) throws IOException {
  this(new FileInputStream(cramFile),indexFile,referenceSource,validationStringency);
  this.cramFile=cramFile;
}

Fixed version (ground truth):
/** 
 * Create a CRAMFileReader from a CRAM file and optional index file using the supplied reference source and validation stringency.
 * @param cramFile        CRAM stream to read. May not be null.
 * @param indexFile       index file to be used for random access. May be null.
 * @param referenceSource a {@link htsjdk.samtools.cram.ref.CRAMReferenceSource source} ofreference sequences. May not be null.
 * @param validationStringency Validation stringency to be used when reading
 * @throws IllegalArgumentException if the {@code cramFile} or the {@code CRAMReferenceSource} is null
 */
public CRAMFileReader(final File cramFile,final File indexFile,final CRAMReferenceSource referenceSource,final ValidationStringency validationStringency) throws IOException {
  this(new FileInputStream(cramFile),indexFile,referenceSource,validationStringency);
  this.cramFile=cramFile;
}
Program: 30462
Project: 30462
Buggy source:
/** 
 * Create a CRAMFileWriter and optional index on output streams.
 * @param outputStream where to write the output. Can not be null.
 * @param indexOS where to write the output index. Can be null if no index is required.
 * @param presorted if true records written to this writer must already be sorted in the order specified by the header
 * @param referenceSource reference source
 * @param samFileHeader {@link SAMFileHeader} to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
 * @param fileName used for display in error message display
 * @throws IllegalArgumentException if the {@code outputStream},   {@code referenceSource} or {@code samFileHeader} are null
 */
public CRAMFileWriter(final OutputStream outputStream,final OutputStream indexOS,final boolean presorted,final ReferenceSource referenceSource,final SAMFileHeader samFileHeader,final String fileName){
  if (outputStream == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (referenceSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (samFileHeader == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.samFileHeader=samFileHeader;
  this.fileName=fileName;
  setSortOrder(samFileHeader.getSortOrder(),presorted);
  cramContainerStream=new CRAMContainerStreamWriter(outputStream,indexOS,referenceSource,samFileHeader,fileName);
  setHeader(samFileHeader);
}

Fixed version (ground truth):
/** 
 * Create a CRAMFileWriter and optional index on output streams.
 * @param outputStream where to write the output. Can not be null.
 * @param indexOS where to write the output index. Can be null if no index is required.
 * @param presorted if true records written to this writer must already be sorted in the order specified by the header
 * @param referenceSource reference source
 * @param samFileHeader {@link SAMFileHeader} to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
 * @param fileName used for display in error message display
 * @throws IllegalArgumentException if the {@code outputStream},   {@code referenceSource} or {@code samFileHeader} are null
 */
public CRAMFileWriter(final OutputStream outputStream,final OutputStream indexOS,final boolean presorted,final CRAMReferenceSource referenceSource,final SAMFileHeader samFileHeader,final String fileName){
  if (outputStream == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (referenceSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (samFileHeader == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.samFileHeader=samFileHeader;
  this.fileName=fileName;
  setSortOrder(samFileHeader.getSortOrder(),presorted);
  cramContainerStream=new CRAMContainerStreamWriter(outputStream,indexOS,referenceSource,samFileHeader,fileName);
  setHeader(samFileHeader);
}
Program: 30463
Project: 30463
Buggy source:
@Deprecated public CRAMIterator(final SeekableStream seekableStream,final ReferenceSource referenceSource,final long[] coordinates) throws IOException {
  this(seekableStream,referenceSource,coordinates,ValidationStringency.DEFAULT_STRINGENCY);
}

Fixed version (ground truth):
@Deprecated public CRAMIterator(final SeekableStream seekableStream,final CRAMReferenceSource referenceSource,final long[] coordinates) throws IOException {
  this(seekableStream,referenceSource,coordinates,ValidationStringency.DEFAULT_STRINGENCY);
}
Program: 30464
Project: 30464
Buggy source:
@Override public SamReaderFactory referenceSource(final ReferenceSource referenceSource){
  this.referenceSource=referenceSource;
  return this;
}

Fixed version (ground truth):
@Override public SamReaderFactory referenceSource(final CRAMReferenceSource referenceSource){
  this.referenceSource=referenceSource;
  return this;
}
Program: 30465
Project: 30465
Buggy source:
public CramNormalizer(final SAMFileHeader header,final ReferenceSource referenceSource){
  if (referenceSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.header=header;
  this.referenceSource=referenceSource;
}

Fixed version (ground truth):
public CramNormalizer(final SAMFileHeader header,final CRAMReferenceSource referenceSource){
  if (referenceSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.header=header;
  this.referenceSource=referenceSource;
}
Program: 30466
Project: 30466
Buggy source:
/** 
 * Attempts to construct a default ReferenceSource for use with CRAM files when one has not been explicitly provided.
 * @return ReferenceSource if one can be acquired. Guaranteed to no be null if noneof the listed exceptions is thrown.
 * @throws IllegalStateException if no default reference source can be acquired
 * @throws IllegalArgumentException if the reference_fasta environment variable refers to aa file that doesn't exist <p> Construct a default reference source to use when an explicit reference has not been provided by checking for fallback sources in this order: <p><ul> <li>Defaults.REFERENCE_FASTA - the value of the system property "reference_fasta". If set, must refer to a valid reference file.</li> <li>ENA Reference Service if it is enabled</li> </ul>
 */
public static ReferenceSource getDefaultCRAMReferenceSource(){
  if (null != Defaults.REFERENCE_FASTA) {
    if (Defaults.REFERENCE_FASTA.exists()) {
      return new ReferenceSource(Defaults.REFERENCE_FASTA);
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + Defaults.REFERENCE_FASTA.getName());
    }
  }
 else   if (Defaults.USE_CRAM_REF_DOWNLOAD) {
    return new ReferenceSource();
  }
 else {
    throw new IllegalStateException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Attempts to construct a default CRAMReferenceSource for use with CRAM files when one has not been explicitly provided.
 * @return CRAMReferenceSource if one can be acquired. Guaranteed to not be null if noneof the listed exceptions is thrown.
 * @throws IllegalStateException if no default reference source can be acquired
 * @throws IllegalArgumentException if the reference_fasta environment variable refers to aa file that doesn't exist <p> Construct a default reference source to use when an explicit reference has not been provided by checking for fallback sources in this order: <p><ul> <li>Defaults.REFERENCE_FASTA - the value of the system property "reference_fasta". If set, must refer to a valid reference file.</li> <li>ENA Reference Service if it is enabled</li> </ul>
 */
public static CRAMReferenceSource getDefaultCRAMReferenceSource(){
  if (null != Defaults.REFERENCE_FASTA) {
    if (Defaults.REFERENCE_FASTA.exists()) {
      return new ReferenceSource(Defaults.REFERENCE_FASTA);
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + Defaults.REFERENCE_FASTA.getName());
    }
  }
 else   if (Defaults.USE_CRAM_REF_DOWNLOAD) {
    return new ReferenceSource();
  }
 else {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 30467
Project: 30467
Buggy source:
/** 
 * If true, uses the caching version of the index reader.
 * @param enabled true to write source information into each SAMRecord.
 */
protected void enableIndexCaching(final boolean enabled){
  if (mIndex != null)   throw new SAMException("String_Node_Str");
  this.mEnableIndexCaching=enabled;
}

Fixed version (ground truth):
/** 
 * If true, uses the caching version of the index reader.
 * @param enabled true to use the caching version of the reader.
 */
protected void enableIndexCaching(final boolean enabled){
  if (mIndex != null)   throw new SAMException("String_Node_Str");
  this.mEnableIndexCaching=enabled;
}
Program: 30468
Project: 30468
Buggy source:
/** 
 * Prepare to index a BAM.
 * @param output     Index will be written here.  output will be closed when finish() method is called.
 * @param fileHeader header for the corresponding bam file.
 */
public BAMIndexer(final OutputStream output,final SAMFileHeader fileHeader){
  numReferences=fileHeader.getSequenceDictionary().size();
  indexBuilder=new BAMIndexBuilder(fileHeader.getSequenceDictionary());
  outputWriter=new BinaryBAMIndexWriter(numReferences,output);
}

Fixed version (ground truth):
private BAMIndexer(final SAMFileHeader fileHeader,Function<Integer,BinaryBAMIndexWriter> createWriter){
  if (fileHeader.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
    if (fileHeader.getSortOrder() == SAMFileHeader.SortOrder.unsorted) {
      log.warn("String_Node_Str");
    }
 else {
      throw new SAMException("String_Node_Str");
    }
  }
  numReferences=fileHeader.getSequenceDictionary().size();
  indexBuilder=new BAMIndexBuilder(fileHeader.getSequenceDictionary());
  outputWriter=createWriter.apply(numReferences);
}
Program: 30469
Project: 30469
Buggy source:
public SAMBinaryTagAndUnsignedArrayValue(final short tag,final Object value){
  super(tag,value);
}

Fixed version (ground truth):
public SAMBinaryTagAndUnsignedArrayValue(final short tag,final Object value){
  super(tag,value);
  if (!value.getClass().isArray() || value instanceof float[]) {
    throw new IllegalArgumentException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
  }
}
Program: 30470
Project: 30470
Buggy source:
@Override public int hashCode(){
  int result=(int)tag;
  result=31 * result + value.hashCode();
  return result;
}

Fixed version (ground truth):
@Override public int hashCode(){
  int valueHash;
  if (this.value instanceof byte[]) {
    valueHash=Arrays.hashCode((byte[])this.value);
  }
 else   if (this.value instanceof short[]) {
    valueHash=Arrays.hashCode((short[])this.value);
  }
 else   if (this.value instanceof int[]) {
    valueHash=Arrays.hashCode((int[])this.value);
  }
 else   if (this.value instanceof float[]) {
    valueHash=Arrays.hashCode((float[])this.value);
  }
 else {
    valueHash=value.hashCode();
  }
  return 31 * tag + valueHash;
}
Program: 30471
Project: 30471
Buggy source:
/** 
 * Type safe equals method that recurses down the list looking for equality. 
 */
private boolean typeSafeEquals(final SAMBinaryTagAndValue that){
  if (this.tag != that.tag)   return false;
  if ((this.value == null) ? that.value == null : this.value.equals(that.value)) {
    if (this.next == null)     return that.next == null;
 else     return this.next.equals(that.next);
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Type safe equals method that recurses down the list looking for equality. 
 */
private boolean typeSafeEquals(final SAMBinaryTagAndValue that){
  if (this.tag != that.tag)   return false;
  if (this.valueEquals(that)) {
    if (this.next == null)     return that.next == null;
 else     return this.next.equals(that.next);
  }
 else {
    return false;
  }
}
Program: 30472
Project: 30472
Buggy source:
/** 
 * @param tag tagname (in binary form) for this attribute
 * @param value value for this attribute (must be of a type that implements {@link Serializable} or else serialization will fail)Cannot be null.
 */
public SAMBinaryTagAndValue(final short tag,final Object value){
  if (null == value) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.tag=tag;
  this.value=value;
}

Fixed version (ground truth):
/** 
 * @param tag tagname (in binary form) for this attribute
 * @param value value for this attribute (must be of a type that implements {@link Serializable}or else serialization will fail). Cannot be null.
 */
public SAMBinaryTagAndValue(final short tag,final Object value){
  if (null == value) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (!isAllowedAttributeValue(value)) {
    throw new IllegalArgumentException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
  }
  this.tag=tag;
  this.value=value;
}
Program: 30473
Project: 30473
Buggy source:
/** 
 * If true, uses the caching version of the index reader.
 * @param enabled true to write source information into each SAMRecord.
 */
public void enableIndexCaching(final boolean enabled){
  if (mIndex != null)   throw new SAMException("String_Node_Str");
  mReader.enableIndexCaching(enabled);
}

Fixed version (ground truth):
/** 
 * If true, uses the caching version of the index reader.
 * @param enabled true to use the caching version of the reader.
 */
public void enableIndexCaching(final boolean enabled){
  if (mIndex != null)   throw new SAMException("String_Node_Str");
  mReader.enableIndexCaching(enabled);
}
Program: 30474
Project: 30474
Buggy source:
/** 
 * Checks if the value is allowed as an attribute value.
 * @param value the value to be checked
 * @return true if the value is valid and false otherwise
 */
protected static boolean isAllowedAttributeValue(final Object value){
  if (value instanceof Byte || value instanceof Short || value instanceof Integer|| value instanceof String|| value instanceof Character|| value instanceof Float|| value instanceof byte[]|| value instanceof short[]|| value instanceof int[]|| value instanceof float[]) {
    return true;
  }
  if (value instanceof Long) {
    return SAMUtils.isValidUnsignedIntegerAttribute((Long)value) || ((Long)value >= Integer.MIN_VALUE && (Long)value <= Integer.MAX_VALUE);
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Checks if the value is allowed as an attribute value.
 * @param value the value to be checked
 * @return true if the value is valid and false otherwise
 * @deprecated The attribute type and value checks have been moved directly into {@code SAMBinaryTagAndValue}.
 */
@Deprecated protected static boolean isAllowedAttributeValue(final Object value){
  return SAMBinaryTagAndValue.isAllowedAttributeValue(value);
}
Program: 30475
Project: 30475
Buggy source:
protected void setAttribute(final short tag,final Object value,final boolean isUnsignedArray){
  if (value == null) {
    if (this.mAttributes != null) {
      this.mAttributes=this.mAttributes.remove(tag);
    }
    return;
  }
  if (isAllowedAttributeValue(value)) {
    final SAMBinaryTagAndValue tmp;
    if (!isUnsignedArray) {
      tmp=new SAMBinaryTagAndValue(tag,value);
    }
 else {
      if (!value.getClass().isArray() || value instanceof float[]) {
        throw new SAMException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
      }
      tmp=new SAMBinaryTagAndUnsignedArrayValue(tag,value);
    }
    if (this.mAttributes == null) {
      this.mAttributes=tmp;
    }
 else {
      this.mAttributes=this.mAttributes.insert(tmp);
    }
  }
 else {
    throw new SAMException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
  }
}

Fixed version (ground truth):
protected void setAttribute(final short tag,final Object value,final boolean isUnsignedArray){
  if (value == null) {
    if (this.mAttributes != null) {
      this.mAttributes=this.mAttributes.remove(tag);
    }
  }
 else {
    final SAMBinaryTagAndValue tmp;
    if (!isUnsignedArray) {
      tmp=new SAMBinaryTagAndValue(tag,value);
    }
 else {
      tmp=new SAMBinaryTagAndUnsignedArrayValue(tag,value);
    }
    if (this.mAttributes == null) {
      this.mAttributes=tmp;
    }
 else {
      this.mAttributes=this.mAttributes.insert(tmp);
    }
  }
}
Program: 30476
Project: 30476
Buggy source:
/** 
 * Returns a deep copy of the SAM record, with the following exceptions: - The header field, which shares the reference with the original record - The file source field, which will always always be set to null in the copy Note that some fields, i.e. the cigar elements, alignment blocks, and indexing bin, are not explicitly populated in the copy since they are lazily generated on demand. Also note that this fails: original.deepCopy().equals(original) due to the fact that SAMBinaryTagAndValue.equals winds up calling object.equals on the value field, which uses reference equality.
 */
public SAMRecord deepCopy(){
  final SAMRecord newSAM=new SAMRecord(getHeader());
  newSAM.setReadName(getReadName());
  newSAM.setReadBases(Arrays.copyOf(getReadBases(),getReadLength()));
  final byte baseQualities[]=getBaseQualities();
  newSAM.setBaseQualities(Arrays.copyOf(baseQualities,baseQualities.length));
  newSAM.setReferenceName(getReferenceName());
  newSAM.setAlignmentStart(getAlignmentStart());
  newSAM.setMappingQuality(getMappingQuality());
  newSAM.setCigarString(getCigarString());
  newSAM.setFileSource(null);
  newSAM.setFlags(getFlags());
  newSAM.setMateReferenceName(getMateReferenceName());
  newSAM.setMateAlignmentStart(getMateAlignmentStart());
  newSAM.setInferredInsertSize(getInferredInsertSize());
  if (null != getHeader()) {
    newSAM.setReferenceIndex(getReferenceIndex());
    newSAM.setMateReferenceIndex(getMateReferenceIndex());
  }
 else {
    newSAM.mReferenceIndex=null;
    newSAM.mMateReferenceIndex=null;
  }
  newSAM.setValidationStringency(getValidationStringency());
  SAMBinaryTagAndValue attributes=getBinaryAttributes();
  if (null != attributes) {
    newSAM.setAttributes(attributes.deepCopy());
  }
  return newSAM;
}

Fixed version (ground truth):
/** 
 * Returns a deep copy of the SAM record, with the following exceptions: - The header field, which shares the header reference with the original record - The file source field, which will always always be set to null in the copy
 */
public SAMRecord deepCopy(){
  final SAMRecord newSAM=new SAMRecord(getHeader());
  newSAM.setReadName(getReadName());
  newSAM.setReadBases(Arrays.copyOf(getReadBases(),getReadLength()));
  final byte baseQualities[]=getBaseQualities();
  newSAM.setBaseQualities(Arrays.copyOf(baseQualities,baseQualities.length));
  newSAM.setReferenceName(getReferenceName());
  newSAM.setAlignmentStart(getAlignmentStart());
  newSAM.setMappingQuality(getMappingQuality());
  newSAM.setCigarString(getCigarString());
  newSAM.setFileSource(null);
  newSAM.setFlags(getFlags());
  newSAM.setMateReferenceName(getMateReferenceName());
  newSAM.setMateAlignmentStart(getMateAlignmentStart());
  newSAM.setInferredInsertSize(getInferredInsertSize());
  newSAM.mReferenceIndex=this.mReferenceIndex;
  newSAM.mMateReferenceIndex=this.mMateReferenceIndex;
  newSAM.setValidationStringency(getValidationStringency());
  SAMBinaryTagAndValue attributes=getBinaryAttributes();
  if (null != attributes) {
    newSAM.setAttributes(attributes.deepCopy());
  }
  newSAM.setIndexingBin(getIndexingBin());
  return newSAM;
}
Program: 30477
Project: 30477
Buggy source:
void setAttribute(final short tag,final Object value,final boolean isUnsignedArray){
  if (value != null && !(value instanceof Byte || value instanceof Short || value instanceof Integer|| value instanceof String|| value instanceof Character|| value instanceof Float|| value instanceof byte[]|| value instanceof short[]|| value instanceof int[]|| value instanceof float[])) {
    throw new SAMException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
  }
  if (value == null) {
    if (this.sliceTags != null)     this.sliceTags=this.sliceTags.remove(tag);
  }
 else {
    final SAMBinaryTagAndValue tmp;
    if (!isUnsignedArray) {
      tmp=new SAMBinaryTagAndValue(tag,value);
    }
 else {
      if (!value.getClass().isArray() || value instanceof float[]) {
        throw new SAMException("String_Node_Str" + value.getClass() + "String_Node_Str"+ SAMTagUtil.getSingleton().makeStringTag(tag));
      }
      tmp=new SAMBinaryTagAndUnsignedArrayValue(tag,value);
    }
    if (this.sliceTags == null)     this.sliceTags=tmp;
 else     this.sliceTags=this.sliceTags.insert(tmp);
  }
}

Fixed version (ground truth):
void setAttribute(final short tag,final Object value,final boolean isUnsignedArray){
  if (value == null) {
    if (this.sliceTags != null)     this.sliceTags=this.sliceTags.remove(tag);
  }
 else {
    final SAMBinaryTagAndValue tmp;
    if (!isUnsignedArray) {
      tmp=new SAMBinaryTagAndValue(tag,value);
    }
 else {
      tmp=new SAMBinaryTagAndUnsignedArrayValue(tag,value);
    }
    if (this.sliceTags == null)     this.sliceTags=tmp;
 else     this.sliceTags=this.sliceTags.insert(tmp);
  }
}
Program: 30478
Project: 30478
Buggy source:
/** 
 * @param chr   the chromosome
 * @param start the start position, one-based, inclusive.
 * @param end   the end position, one-based, inclusive.
 * @return List of regions of file that are candidates for the given query.<p/> TODO: This method has not yet been tested, since the primary task is index writing.
 */
@Override public List<Block> getBlocks(final String chr,final int start,final int end){
  final int sequenceIndex=sequenceNames.indexOf(chr);
  if (sequenceIndex == -1 || indices[sequenceIndex] == null) {
    return Collections.emptyList();
  }
  final List<Chunk> chunks=indices[sequenceIndex].getChunksOverlapping(start,end);
  final List<Block> ret=new ArrayList<Block>(chunks.size());
  for (  final Chunk chunk : chunks) {
    ret.add(new Block(chunk.getChunkStart(),chunk.getChunkEnd() - chunk.getChunkStart()));
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * @param chr   the chromosome
 * @param start the start position, one-based, inclusive.
 * @param end   the end position, one-based, inclusive.
 * @return List of regions of file that are candidates for the given query.<p/> TODO: This method has not yet been tested, since the primary task is index writing.
 */
@Override public List<Block> getBlocks(final String chr,final int start,final int end){
  final int sequenceIndex=sequenceNames.indexOf(chr);
  if (sequenceIndex == -1 || indices[sequenceIndex] == null) {
    return Collections.emptyList();
  }
  final List<Chunk> chunks=indices[sequenceIndex].getChunksOverlapping(start,end);
  if (chunks == null) {
    return Collections.emptyList();
  }
 else {
    final List<Block> ret=new ArrayList<>(chunks.size());
    chunks.stream().map(chunk -> new Block(chunk.getChunkStart(),chunk.getChunkEnd() - chunk.getChunkStart())).forEach(ret::add);
    return ret;
  }
}
Program: 30479
Project: 30479
Buggy source:
public final static boolean canDecodeFile(final String potentialInput,final String MAGIC_HEADER_LINE){
  try (final FileInputStream fis=new FileInputStream(potentialInput);final GZIPInputStream gis=new GZIPInputStream(new FileInputStream(potentialInput));final BlockCompressedInputStream bcis=new BlockCompressedInputStream(new FileInputStream(potentialInput))){
    return isVCFStream(fis,MAGIC_HEADER_LINE) || isVCFStream(gis,MAGIC_HEADER_LINE) || isVCFStream(bcis,MAGIC_HEADER_LINE);
  }
 catch (  FileNotFoundException e) {
    return false;
  }
catch (  IOException e) {
    return false;
  }
}

Fixed version (ground truth):
public static boolean canDecodeFile(final String potentialInput,final String MAGIC_HEADER_LINE){
  try {
    return isVCFStream(new FileInputStream(potentialInput),MAGIC_HEADER_LINE) || isVCFStream(new GZIPInputStream(new FileInputStream(potentialInput)),MAGIC_HEADER_LINE) || isVCFStream(new BlockCompressedInputStream(new FileInputStream(potentialInput)),MAGIC_HEADER_LINE);
  }
 catch (  FileNotFoundException e) {
    return false;
  }
catch (  IOException e) {
    return false;
  }
}
Program: 30480
Project: 30480
Buggy source:
private final static boolean isVCFStream(final InputStream stream,final String MAGIC_HEADER_LINE){
  try {
    byte[] buff=new byte[MAGIC_HEADER_LINE.length()];
    int nread=stream.read(buff,0,MAGIC_HEADER_LINE.length());
    boolean eq=Arrays.equals(buff,MAGIC_HEADER_LINE.getBytes());
    return eq;
  }
 catch (  IOException e) {
    return false;
  }
catch (  RuntimeException e) {
    return false;
  }
 finally {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}

Fixed version (ground truth):
private static boolean isVCFStream(final InputStream stream,final String MAGIC_HEADER_LINE){
  try {
    byte[] buff=new byte[MAGIC_HEADER_LINE.length()];
    int nread=stream.read(buff,0,MAGIC_HEADER_LINE.length());
    boolean eq=Arrays.equals(buff,MAGIC_HEADER_LINE.getBytes());
    return eq;
  }
 catch (  IOException e) {
    return false;
  }
catch (  RuntimeException e) {
    return false;
  }
 finally {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}