nus-yam/ex-repair huggingface dataset:
Program: 30481
Project: 30481
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: 30482
Project: 30482
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) {
    }
  }
}
Program: 30483
Project: 30483
Buggy source:
/** 
 * Establishes the SAMFileHeader for this record and forces resolution of the record's reference and mate reference names against the header using the sequence dictionary in the new header. If either the reference or mate reference name does not appear in the new header's sequence dictionary, an IllegalArgumentException is thrown.
 * @param header new header for this record. Can not be null.
 * @throws IllegalArgumentException if the record has reference or mate reference names that cannot be resolvedto indices using the new header.
 */
public void setHeaderStrict(final SAMFileHeader header){
  if (null == header) {
    mReferenceIndex=null;
    mMateReferenceIndex=null;
  }
 else {
    Integer referenceIndex=resolveIndexFromName(mReferenceName,header,true);
    Integer mateReferenceIndex=resolveIndexFromName(mMateReferenceName,header,true);
    mReferenceIndex=referenceIndex;
    mMateReferenceIndex=mateReferenceIndex;
    this.mHeader=header;
  }
}

Fixed version (ground truth):
/** 
 * Establishes the SAMFileHeader for this record and forces resolution of the record's reference and mate reference names against the header using the sequence dictionary in the new header. If either the reference or mate reference name does not appear in the new header's sequence dictionary, an IllegalArgumentException is thrown.
 * @param header new header for this record. May be null.
 * @throws IllegalArgumentException if the record has reference or mate reference names that cannot be resolvedto indices using the new header.
 */
public void setHeaderStrict(final SAMFileHeader header){
  if (null == header) {
    mReferenceIndex=null;
    mMateReferenceIndex=null;
  }
 else {
    Integer referenceIndex=resolveIndexFromName(mReferenceName,header,true);
    Integer mateReferenceIndex=resolveIndexFromName(mMateReferenceName,header,true);
    mReferenceIndex=referenceIndex;
    mMateReferenceIndex=mateReferenceIndex;
  }
  this.mHeader=header;
}
Program: 30484
Project: 30484
Buggy source:
@Test public void testSetHeaderStrictNull(){
  SAMRecord sam=createTestRecordHelper();
  sam.setHeaderStrict(null);
  Assert.assertEquals(sam.mReferenceIndex,null);
}

Fixed version (ground truth):
@Test public void testSetHeaderStrictNull(){
  SAMRecord sam=createTestRecordHelper();
  Assert.assertNotNull(sam.getHeader());
  sam.setHeaderStrict(null);
  Assert.assertNull(sam.getHeader());
  Assert.assertNull(sam.mReferenceIndex);
}
Program: 30486
Project: 30486
Buggy source:
public CRAMFileWriter(final OutputStream outputStream,final OutputStream indexOS,final ReferenceSource source,final SAMFileHeader samFileHeader,final String fileName){
  this.outputStream=outputStream;
  this.source=source;
  this.samFileHeader=samFileHeader;
  this.fileName=fileName;
  setSortOrder(samFileHeader.getSortOrder(),true);
  setHeader(samFileHeader);
  if (this.source == null)   this.source=new ReferenceSource(Defaults.REFERENCE_FASTA);
  containerFactory=new ContainerFactory(samFileHeader,recordsPerSlice);
  if (indexOS != null)   indexer=new CRAMIndexer(indexOS,samFileHeader);
}

Fixed version (ground truth):
/** 
 * Create a CRAMFileWriter and index on output streams.
 * @param outputStream where to write the output.
 * @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 source reference source
 * @param samFileHeader {@link SAMFileHeader} to be used. Sort order is determined by the sortOrder property of this arg.
 * @param fileName used for display in error message display
 */
public CRAMFileWriter(final OutputStream outputStream,final OutputStream indexOS,final boolean presorted,final ReferenceSource source,final SAMFileHeader samFileHeader,final String fileName){
  this.outputStream=outputStream;
  this.samFileHeader=samFileHeader;
  this.fileName=fileName;
  initCRAMWriter(indexOS,source,samFileHeader,presorted);
}
Program: 30487
Project: 30487
Buggy source:
@Override protected void finish(){
  try {
    if (!samRecords.isEmpty())     flushContainer();
    CramIO.issueEOF(cramVersion,outputStream);
    outputStream.flush();
    if (indexer != null)     indexer.finish();
  }
 catch (  final RuntimeException re) {
    throw re;
  }
catch (  final Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@Override protected void finish(){
  try {
    if (!samRecords.isEmpty()) {
      flushContainer();
    }
    CramIO.issueEOF(cramVersion,outputStream);
    outputStream.flush();
    if (indexer != null) {
      indexer.finish();
    }
    outputStream.close();
  }
 catch (  final IOException e) {
    throw new RuntimeIOException(e);
  }
catch (  final IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
Program: 30488
Project: 30488
Buggy source:
/** 
 * Write an alignment record.
 * @param alignment must not be null and must have a valid SAMFileHeader.
 */
@Override protected void writeAlignment(final SAMRecord alignment){
  if (shouldFlushContainer(alignment))   try {
    flushContainer();
  }
 catch (  final Exception e) {
    throw new RuntimeException(e);
  }
  updateReferenceContext(alignment.getReferenceIndex());
  samRecords.add(alignment);
}

Fixed version (ground truth):
/** 
 * Write an alignment record.
 * @param alignment must not be null and must have a valid SAMFileHeader.
 */
@Override protected void writeAlignment(final SAMRecord alignment){
  if (shouldFlushContainer(alignment)) {
    try {
      flushContainer();
    }
 catch (    IOException e) {
      throw new RuntimeIOException(e);
    }
catch (    IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
  updateReferenceContext(alignment.getReferenceIndex());
  samRecords.add(alignment);
}
Program: 30489
Project: 30489
Buggy source:
/** 
 * Convenience method allowing newSAMFileWriterFactory().setCreateIndex(true); Equivalent to SAMFileWriterFactory.setDefaultCreateIndexWhileWriting(true); newSAMFileWriterFactory(); If a BAM (not SAM) file is created, the setting is true, and the file header specifies coordinate order, then a BAM index file will be written along with the BAM file.
 * @param setting whether to attempt to create a BAM index while creating the BAM file.
 * @return this factory object
 */
public SAMFileWriterFactory setCreateIndex(final boolean setting){
  this.createIndex=setting;
  return this;
}

Fixed version (ground truth):
/** 
 * Convenience method allowing newSAMFileWriterFactory().setCreateIndex(true); Equivalent to SAMFileWriterFactory.setDefaultCreateIndexWhileWriting(true); newSAMFileWriterFactory(); If a BAM or CRAM (not SAM) file is created, the setting is true, and the file header specifies coordinate order, then a BAM index file will be written along with the BAM file.
 * @param setting whether to attempt to create a BAM index while creating the BAM file.
 * @return this factory object
 */
public SAMFileWriterFactory setCreateIndex(final boolean setting){
  this.createIndex=setting;
  return this;
}
Program: 30490
Project: 30490
Buggy source:
public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header,final File outputFile,final File referenceFasta){
  final boolean createIndex=this.createIndex && IOUtil.isRegularPath(outputFile);
  if (this.createIndex && !createIndex) {
    System.err.println("String_Node_Str" + outputFile.getAbsolutePath());
  }
  try {
    OutputStream indexOS=null;
    if (createIndex) {
      File indexFile=new File(outputFile.getAbsolutePath() + "String_Node_Str");
      indexOS=new FileOutputStream(indexFile);
    }
    final CRAMFileWriter writer=new CRAMFileWriter(new FileOutputStream(outputFile),indexOS,new ReferenceSource(referenceFasta),header,null);
    writer.setPreserveReadNames(true);
    writer.setCaptureAllTags(true);
    return writer;
  }
 catch (  final IOException ioe) {
    throw new RuntimeIOException("String_Node_Str" + outputFile.getAbsolutePath());
  }
}

Fixed version (ground truth):
/** 
 * Create a CRAMFileWriter on an output file. Note: does not honor factory setting for USE_ASYNC_IO.
 * @param header entire header. Sort order is determined by the sortOrder property of this arg.
 * @param presorted  if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.
 * @param outputFile where to write the output.  Must end with .sam, .bam or .cram.
 * @param referenceFasta reference sequence file
 * @return CRAMFileWriter
 */
public CRAMFileWriter makeCRAMWriter(final SAMFileHeader header,final boolean presorted,final File outputFile,final File referenceFasta){
  return createCRAMWriterWithSettings(header,presorted,outputFile,referenceFasta);
}
Program: 30491
Project: 30491
Buggy source:
public SAMFileWriter makeWriter(final SAMFileHeader header,final boolean presorted,final File outputFile,final File referenceFasta){
  if (outputFile.getName().endsWith(SamReader.Type.CRAM_TYPE.fileExtension()))   try {
    return makeCRAMWriter(header,new FileOutputStream(outputFile),referenceFasta);
  }
 catch (  final FileNotFoundException e) {
    throw new RuntimeIOException(e);
  }
  return makeSAMOrBAMWriter(header,presorted,outputFile);
}

Fixed version (ground truth):
/** 
 * Create a SAM, BAM or CRAM writer based on examination of the outputFile extension.
 * @param header header. Sort order is determined by the sortOrder property of this arg.
 * @param presorted if true, SAMRecords must be added to the SAMFileWriter in order that agrees with header.sortOrder.
 * @param outputFile where to write the output.  Must end with .sam, .bam or .cram.
 * @param referenceFasta reference sequence file
 * @return SAMFileWriter appropriate for the file type specified in outputFile
 */
public SAMFileWriter makeWriter(final SAMFileHeader header,final boolean presorted,final File outputFile,final File referenceFasta){
  if (outputFile.getName().endsWith(SamReader.Type.CRAM_TYPE.fileExtension())) {
    return makeCRAMWriter(header,presorted,outputFile,referenceFasta);
  }
 else {
    return makeSAMOrBAMWriter(header,presorted,outputFile);
  }
}
Program: 30492
Project: 30492
Buggy source:
private void validateSortOrder(final SAMRecord record,final long recordNumber){
  final SAMRecord prev=orderChecker.getPreviousRecord();
  if (!orderChecker.isSorted(record)) {
    addError(new SAMValidationError(Type.RECORD_OUT_OF_ORDER,String.format("String_Node_Str",record.getHeader().getSortOrder().name(),prev.getReadName(),prev.getReferenceIndex(),prev.getAlignmentStart()),record.getReadName(),recordNumber));
  }
}

Fixed version (ground truth):
private boolean validateSortOrder(final SAMRecord record,final long recordNumber){
  final SAMRecord prev=orderChecker.getPreviousRecord();
  boolean isValidSortOrder=orderChecker.isSorted(record);
  if (!isValidSortOrder) {
    addError(new SAMValidationError(Type.RECORD_OUT_OF_ORDER,String.format("String_Node_Str",record.getHeader().getSortOrder().name(),prev.getReadName(),prev.getReferenceIndex(),prev.getAlignmentStart()),record.getReadName(),recordNumber));
  }
  return isValidSortOrder;
}
Program: 30494
Project: 30494
Buggy source:
/** 
 * Run all validations of the mate's CIGAR.  These include validation that the CIGAR makes sense independent of placement, plus validation that CIGAR + placement yields all bases with M operator within the range of the reference.
 * @param rec the SAM record
 * @param recordNumber For error reporting.  -1 if not known.
 * @return List of errors, or null if no errors.
 */
public static List<SAMValidationError> validateMateCigar(final SAMRecord rec,final long recordNumber){
  List<SAMValidationError> ret=null;
  if (rec.getValidationStringency() != ValidationStringency.SILENT) {
    if (rec.getReadPairedFlag() && !rec.getMateUnmappedFlag()) {
      if (getMateCigarString(rec) != null) {
        ret=SAMUtils.validateCigar(rec,getMateCigar(rec),rec.getMateReferenceIndex(),getMateAlignmentBlocks(rec),recordNumber,"String_Node_Str");
      }
    }
 else {
      if (getMateCigarString(rec) != null) {
        ret=new ArrayList<SAMValidationError>();
        if (rec.getMateUnmappedFlag()) {
          ret.add(new SAMValidationError(SAMValidationError.Type.MATE_CIGAR_STRING_INVALID_PRESENCE,"String_Node_Str",rec.getReadName(),recordNumber));
        }
 else {
          ret.add(new SAMValidationError(SAMValidationError.Type.MATE_CIGAR_STRING_INVALID_PRESENCE,"String_Node_Str",rec.getReadName(),recordNumber));
        }
      }
    }
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Run all validations of the mate's CIGAR.  These include validation that the CIGAR makes sense independent of placement, plus validation that CIGAR + placement yields all bases with M operator within the range of the reference.
 * @param rec the SAM record
 * @param recordNumber For error reporting.  -1 if not known.
 * @return List of errors, or null if no errors.
 */
public static List<SAMValidationError> validateMateCigar(final SAMRecord rec,final long recordNumber){
  List<SAMValidationError> ret=null;
  if (rec.getValidationStringency() != ValidationStringency.SILENT) {
    if (rec.getReadPairedFlag() && !rec.getMateUnmappedFlag()) {
      if (getMateCigarString(rec) != null) {
        ret=SAMUtils.validateCigar(rec,getMateCigar(rec),rec.getMateReferenceIndex(),getMateAlignmentBlocks(rec),recordNumber,"String_Node_Str");
      }
    }
 else {
      if (getMateCigarString(rec) != null) {
        ret=new ArrayList<SAMValidationError>();
        if (!rec.getReadPairedFlag()) {
          ret.add(new SAMValidationError(SAMValidationError.Type.MATE_CIGAR_STRING_INVALID_PRESENCE,"String_Node_Str",rec.getReadName(),recordNumber));
        }
 else {
          ret.add(new SAMValidationError(SAMValidationError.Type.MATE_CIGAR_STRING_INVALID_PRESENCE,"String_Node_Str",rec.getReadName(),recordNumber));
        }
      }
    }
  }
  return ret;
}
Program: 30495
Project: 30495
Buggy source:
/** 
 * Read value of specified non-array type.
 * @param tagType What type to read.
 * @param byteBuffer Little-ending byte buffer to read value from.
 * @return Value in in-memory Object form.
 */
private static Object readSingleValue(final byte tagType,final ByteBuffer byteBuffer,final ValidationStringency validationStringency){
switch (tagType) {
case 'Z':
    return readNullTerminatedString(byteBuffer);
case 'A':
  return (char)byteBuffer.get();
case 'I':
final long val=byteBuffer.getInt() & 0xffffffffL;
if (val <= Integer.MAX_VALUE) {
return (int)val;
}
SAMUtils.processValidationError(new SAMValidationError(SAMValidationError.Type.TAG_VALUE_TOO_LARGE,"String_Node_Str" + val + "String_Node_Str",null),validationStringency);
return val;
case 'i':
return byteBuffer.getInt();
case 's':
return (int)byteBuffer.getShort();
case 'S':
return byteBuffer.getShort() & 0xffff;
case 'c':
return (int)byteBuffer.get();
case 'C':
return (int)byteBuffer.get() & 0xff;
case 'f':
return byteBuffer.getFloat();
case 'H':
final String hexRep=readNullTerminatedString(byteBuffer);
return StringUtil.hexStringToBytes(hexRep);
default :
throw new SAMFormatException("String_Node_Str" + (char)tagType);
}
}

Fixed version (ground truth):
/** 
 * Read value of specified non-array type.
 * @param tagType What type to read.
 * @param byteBuffer Little-ending byte buffer to read value from.
 * @return Value in in-memory Object form.
 */
private static Object readSingleValue(final byte tagType,final ByteBuffer byteBuffer,final ValidationStringency validationStringency){
switch (tagType) {
case 'Z':
    return readNullTerminatedString(byteBuffer);
case 'A':
  return (char)byteBuffer.get();
case 'I':
final long val=byteBuffer.getInt() & 0xffffffffL;
if (val <= Integer.MAX_VALUE) {
return (int)val;
}
if (!SAMUtils.isValidUnsignedIntegerAttribute(val)) {
SAMUtils.processValidationError(new SAMValidationError(SAMValidationError.Type.TAG_VALUE_TOO_LARGE,"String_Node_Str" + val,null),validationStringency);
}
return val;
case 'i':
return byteBuffer.getInt();
case 's':
return (int)byteBuffer.getShort();
case 'S':
return byteBuffer.getShort() & 0xffff;
case 'c':
return (int)byteBuffer.get();
case 'C':
return (int)byteBuffer.get() & 0xff;
case 'f':
return byteBuffer.getFloat();
case 'H':
final String hexRep=readNullTerminatedString(byteBuffer);
return StringUtil.hexStringToBytes(hexRep);
default :
throw new SAMFormatException("String_Node_Str" + (char)tagType);
}
}
Program: 30496
Project: 30496
Buggy source:
@Override protected void finish(){
  try {
    if (!samRecords.isEmpty())     flushContainer();
    CramIO.issueEOF(cramVersion,outputStream);
    outputStream.flush();
    if (indexer != null)     indexer.finish();
  }
 catch (  final Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@Override protected void finish(){
  try {
    if (!samRecords.isEmpty())     flushContainer();
    CramIO.issueEOF(cramVersion,outputStream);
    outputStream.flush();
    if (indexer != null)     indexer.finish();
  }
 catch (  final RuntimeException re) {
    throw re;
  }
catch (  final Exception e) {
    throw new RuntimeException(e);
  }
}
Program: 30497
Project: 30497
Buggy source:
@Override public boolean hasNext(){
  if (container != null && container.isEOF())   return false;
  if (!iterator.hasNext()) {
    try {
      nextContainer();
    }
 catch (    final Exception e) {
      throw new RuntimeEOFException(e);
    }
  }
  return !records.isEmpty();
}

Fixed version (ground truth):
@Override public boolean hasNext(){
  if (container != null && container.isEOF())   return false;
  if (!iterator.hasNext()) {
    try {
      nextContainer();
    }
 catch (    CRAMException ce) {
      throw ce;
    }
catch (    SAMFormatException se) {
      throw se;
    }
catch (    final Exception e) {
      throw new RuntimeEOFException(e);
    }
  }
  return !records.isEmpty();
}
Program: 30499
Project: 30499
Buggy source:
/** 
 * Get the tag value and attempt to coerce it into the requested type.
 * @param tag The requested tag.
 * @return The value of a tag, converted into an Integer if possible.
 * @throws RuntimeException If the value is not an integer type, or will not fit in an Integer.
 */
public Integer getIntegerAttribute(final String tag){
  final Object val=getAttribute(tag);
  if (val == null)   return null;
  if (val instanceof Integer) {
    return (Integer)val;
  }
  if (!(val instanceof Number)) {
    throw new RuntimeException("String_Node_Str" + tag + "String_Node_Str"+ val.getClass());
  }
  final long longVal=((Number)val).longValue();
  if (longVal < Integer.MIN_VALUE || longVal > Integer.MAX_VALUE) {
    throw new RuntimeException("String_Node_Str" + tag + "String_Node_Str"+ longVal);
  }
  return (int)longVal;
}

Fixed version (ground truth):
/** 
 * Get the tag value and attempt to coerce it into the requested type.
 * @param tag The requested tag.
 * @return The value of a tag, converted into a signed Integer if possible.
 * @throws RuntimeException If the value is not an integer type, or will not fit in a signed Integer.
 */
public Integer getIntegerAttribute(final String tag){
  final Object val=getAttribute(tag);
  if (val == null)   return null;
  if (val instanceof Integer) {
    return (Integer)val;
  }
  if (!(val instanceof Number)) {
    throw new RuntimeException("String_Node_Str" + tag + "String_Node_Str"+ val.getClass());
  }
  final long longVal=((Number)val).longValue();
  if (longVal < Integer.MIN_VALUE || longVal > Integer.MAX_VALUE) {
    throw new RuntimeException("String_Node_Str" + tag + "String_Node_Str"+ longVal);
  }
  return (int)longVal;
}
Program: 30500
Project: 30500
Buggy source:
protected 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.mAttributes != null)     this.mAttributes=this.mAttributes.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.mAttributes == null)     this.mAttributes=tmp;
 else     this.mAttributes=this.mAttributes.insert(tmp);
  }
}

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);
    }
    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));
  }
}
Program: 30501
Project: 30501
Buggy source:
/** 
 * Convert in-memory representation of tag to SAM text representation.
 * @param tagName Two-character tag name.
 * @param value Tag value as approriate Object subclass.
 * @return SAM text String representation, i.e. name:type:value
 */
public String encode(final String tagName,Object value){
  final StringBuilder sb=new StringBuilder(tagName);
  sb.append(':');
  char tagType=BinaryTagCodec.getTagValueType(value);
switch (tagType) {
case 'c':
case 'C':
case 's':
case 'S':
case 'I':
    tagType='i';
}
if (tagType == 'H') {
  value=StringUtil.bytesToHexString((byte[])value);
}
 else if (tagType == 'B') {
  value=getArrayType(value,false) + "String_Node_Str" + encodeArrayValue(value);
}
 else if (tagType == 'i') {
  final long longVal=((Number)value).longValue();
  if (longVal > Integer.MAX_VALUE || longVal < Integer.MIN_VALUE) {
    throw new SAMFormatException("String_Node_Str" + tagName + "String_Node_Str"+ longVal);
  }
}
sb.append(tagType);
sb.append(':');
sb.append(value.toString());
return sb.toString();
}

Fixed version (ground truth):
/** 
 * Convert in-memory representation of tag to SAM text representation.
 * @param tagName Two-character tag name.
 * @param value Tag value as approriate Object subclass.
 * @return SAM text String representation, i.e. name:type:value
 */
public String encode(final String tagName,Object value){
  final StringBuilder sb=new StringBuilder(tagName);
  sb.append(':');
  char tagType=BinaryTagCodec.getTagValueType(value);
switch (tagType) {
case 'c':
case 'C':
case 's':
case 'S':
case 'I':
    tagType='i';
}
if (tagType == 'H') {
  value=StringUtil.bytesToHexString((byte[])value);
}
 else if (tagType == 'B') {
  value=getArrayType(value,false) + "String_Node_Str" + encodeArrayValue(value);
}
 else if (tagType == 'i') {
  final long longVal=((Number)value).longValue();
  if (longVal < Integer.MIN_VALUE || longVal > BinaryCodec.MAX_UINT) {
    throw new IllegalArgumentException("String_Node_Str" + tagName + "String_Node_Str"+ longVal);
  }
}
sb.append(tagType);
sb.append(':');
sb.append(value.toString());
return sb.toString();
}
Program: 30502
Project: 30502
Buggy source:
private Object convertStringToObject(final String type,final String stringVal){
  if (type.equals("String_Node_Str")) {
    return stringVal;
  }
 else   if (type.equals("String_Node_Str")) {
    if (stringVal.length() != 1) {
      throw new SAMFormatException("String_Node_Str");
    }
    return stringVal.charAt(0);
  }
 else   if (type.equals("String_Node_Str")) {
    try {
      return new Integer(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
  }
 else   if (type.equals("String_Node_Str")) {
    try {
      return new Float(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
  }
 else   if (type.equals("String_Node_Str")) {
    try {
      return StringUtil.hexStringToBytes(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
  }
 else   if (type.equals("String_Node_Str")) {
    return covertStringArrayToObject(stringVal);
  }
 else {
    throw new SAMFormatException("String_Node_Str" + type);
  }
}

Fixed version (ground truth):
private Object convertStringToObject(final String type,final String stringVal){
  if (type.equals("String_Node_Str")) {
    return stringVal;
  }
 else   if (type.equals("String_Node_Str")) {
    if (stringVal.length() != 1) {
      throw new SAMFormatException("String_Node_Str");
    }
    return stringVal.charAt(0);
  }
 else   if (type.equals("String_Node_Str")) {
    final long lValue;
    try {
      lValue=Long.valueOf(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
    if (lValue >= Integer.MIN_VALUE && lValue <= Integer.MAX_VALUE) {
      return (int)lValue;
    }
 else     if (SAMUtils.isValidUnsignedIntegerAttribute(lValue)) {
      return lValue;
    }
 else {
      throw new SAMFormatException("String_Node_Str" + stringVal);
    }
  }
 else   if (type.equals("String_Node_Str")) {
    try {
      return new Float(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
  }
 else   if (type.equals("String_Node_Str")) {
    try {
      return StringUtil.hexStringToBytes(stringVal);
    }
 catch (    NumberFormatException e) {
      throw new SAMFormatException("String_Node_Str");
    }
  }
 else   if (type.equals("String_Node_Str")) {
    return covertStringArrayToObject(stringVal);
  }
 else {
    throw new SAMFormatException("String_Node_Str" + type);
  }
}
Program: 30503
Project: 30503
Buggy source:
List<CramCompressionRecord> getRecords(final Slice slice,final CompressionHeader header) throws IllegalArgumentException, IllegalAccessException {
  return getRecords(null,slice,header);
}

Fixed version (ground truth):
List<CramCompressionRecord> getRecords(final Slice slice,final CompressionHeader header,ValidationStringency validationStringency) throws IllegalArgumentException, IllegalAccessException {
  return getRecords(null,slice,header,validationStringency);
}
Program: 30505
Project: 30505
Buggy source:
/** 
 * Add the record to the tail of the queue, spilling to disk if necessary Must check that (canAdd() == true) before calling this method
 * @param record The record to be added to the queue
 * @return true (if add successful)
 * @throws IllegalStateException if the queue cannot be added to
 */
public boolean add(final E record) throws IllegalStateException {
  if (!canAdd)   throw new IllegalStateException("String_Node_Str");
  if (this.headRecord == null) {
    this.headRecord=record;
  }
 else   if (this.ramRecords.size() == this.maxRecordsInRamQueue) {
    spillToDisk(record);
  }
 else {
    this.ramRecords.add(record);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Add the record to the tail of the queue, spilling to disk if necessary Must check that (canAdd() == true) before calling this method
 * @param record The record to be added to the queue
 * @return true (if add successful)
 * @throws IllegalStateException if the queue cannot be added to
 */
public boolean add(final E record) throws IllegalStateException {
  if (!canAdd)   throw new IllegalStateException("String_Node_Str");
  if (this.headRecord == null) {
    if (0 < this.numRecordsOnDisk)     throw new SAMException("String_Node_Str");
    this.headRecord=record;
  }
 else   if (this.ramRecords.size() == this.maxRecordsInRamQueue) {
    spillToDisk(record);
  }
 else {
    if (0 < this.numRecordsOnDisk)     throw new SAMException("String_Node_Str");
    this.ramRecords.add(record);
  }
  return true;
}
Program: 30506
Project: 30506
Buggy source:
/** 
 * Syntactic sugar around the ctor, to save some typing of type parameters
 * @param codec For writing records to file and reading them back into RAM
 * @param maxRecordsInRAM how many records to accumulate in memory before spilling to disk
 * @param tmpDir Where to write files of records that will not fit in RAM
 */
public static <T>DiskBackedQueue<T> newInstance(final SortingCollection.Codec<T> codec,final int maxRecordsInRAM,final List<File> tmpDir){
  return new DiskBackedQueue<T>(codec,maxRecordsInRAM,tmpDir);
}

Fixed version (ground truth):
/** 
 * Syntactic sugar around the ctor, to save some typing of type parameters
 * @param codec For writing records to file and reading them back into RAM
 * @param maxRecordsInRam how many records to accumulate in memory before spilling to disk
 * @param tmpDir Where to write files of records that will not fit in RAM
 */
public static <T>DiskBackedQueue<T> newInstance(final SortingCollection.Codec<T> codec,final int maxRecordsInRam,final List<File> tmpDir){
  return new DiskBackedQueue<T>(codec,maxRecordsInRam,tmpDir);
}
Program: 30507
Project: 30507
Buggy source:
/** 
 * Update the head of the queue with the next record in memory or on disk. Sets headRecord to null if the queue is now empty
 */
private void updateQueueHead(){
  if (!this.ramRecords.isEmpty()) {
    this.headRecord=this.ramRecords.poll();
  }
 else   if (this.diskRecords != null) {
    this.headRecord=this.readFileRecord(this.diskRecords);
  }
 else {
    this.headRecord=null;
  }
}

Fixed version (ground truth):
/** 
 * Update the head of the queue with the next record in memory or on disk. Sets headRecord to null if the queue is now empty
 */
private void updateQueueHead(){
  if (!this.ramRecords.isEmpty()) {
    this.headRecord=this.ramRecords.poll();
    if (0 < numRecordsOnDisk)     this.canAdd=false;
  }
 else   if (this.diskRecords != null) {
    this.headRecord=this.readFileRecord(this.diskRecords);
    this.canAdd=false;
  }
 else {
    this.canAdd=true;
    this.headRecord=null;
  }
}
Program: 30508
Project: 30508
Buggy source:
@Test public void testReadOnlyQueueJustBeforeReadingFromDisk(){
  DiskBackedQueue<String> queue=makeDiskBackedQueue(2);
  queue.add("String_Node_Str");
  queue.add("String_Node_Str");
  queue.add("String_Node_Str");
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertFalse(queue.canAdd());
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertEquals(queue.size(),0);
  Assert.assertTrue(queue.isEmpty());
  Assert.assertEquals(queue.poll(),null);
  queue.clear();
  Assert.assertTrue(queue.canAdd());
}

Fixed version (ground truth):
@Test public void testReadOnlyQueueJustBeforeReadingFromDisk(){
  final DiskBackedQueue<String> queue=makeDiskBackedQueue(2);
  queue.add("String_Node_Str");
  queue.add("String_Node_Str");
  queue.add("String_Node_Str");
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertFalse(queue.canAdd());
  Assert.assertEquals("String_Node_Str",queue.poll());
  Assert.assertEquals(queue.size(),0);
  Assert.assertTrue(queue.isEmpty());
  Assert.assertEquals(queue.poll(),null);
  queue.clear();
  Assert.assertTrue(queue.canAdd());
}
Program: 30509
Project: 30509
Buggy source:
private DiskBackedQueue<String> makeDiskBackedQueue(final int maxRecordsInRam){
  return DiskBackedQueue.newInstance(new StringCodec(),maxRecordsInRam,Collections.singletonList(tmpDir));
}

Fixed version (ground truth):
private DiskBackedQueue<String> makeDiskBackedQueue(final int maxRecordsInRam){
  return DiskBackedQueue.newInstance(new StringCodec(),maxRecordsInRam,Collections.singletonList(tmpDir()));
}
Program: 30510
Project: 30510
Buggy source:
protected boolean tmpDirIsEmpty(){
  System.err.println("String_Node_Str" + tmpDir);
  return tmpDir.listFiles().length == 0;
}

Fixed version (ground truth):
protected boolean tmpDirIsEmpty(){
  return tmpDir().listFiles().length == 0;
}
Program: 30511
Project: 30511
Buggy source:
private SortingCollection<String> makeSortingCollection(final int maxRecordsInRam){
  return SortingCollection.newInstance(String.class,new StringCodec(),new StringComparator(),maxRecordsInRam,tmpDir);
}

Fixed version (ground truth):
private SortingCollection<String> makeSortingCollection(final int maxRecordsInRam){
  return SortingCollection.newInstance(String.class,new StringCodec(),new StringComparator(),maxRecordsInRam,tmpDir());
}
Program: 30512
Project: 30512
Buggy source:
/** 
 * Generate some strings, put into SortingCollection, confirm that the right number of Strings come out, and in the right order.
 * @param numStringsToGenerate
 * @param maxRecordsInRam
 */
@Test(dataProvider="String_Node_Str") public void testPositive(final String testName,final int numStringsToGenerate,final int maxRecordsInRam){
  final String[] strings=new String[numStringsToGenerate];
  int numStringsGenerated=0;
  final SortingCollection<String> sortingCollection=makeSortingCollection(maxRecordsInRam);
  for (  final String s : new RandomStringGenerator(numStringsToGenerate)) {
    sortingCollection.add(s);
    strings[numStringsGenerated++]=s;
  }
  Arrays.sort(strings,new StringComparator());
  Assert.assertEquals(tmpDirIsEmpty(),numStringsToGenerate <= maxRecordsInRam);
  sortingCollection.setDestructiveIteration(false);
  assertIteratorEqualsList(strings,sortingCollection.iterator());
  assertIteratorEqualsList(strings,sortingCollection.iterator());
  sortingCollection.cleanup();
  Assert.assertEquals(tmpDir.list().length,0);
}

Fixed version (ground truth):
/** 
 * Generate some strings, put into SortingCollection, confirm that the right number of Strings come out, and in the right order.
 * @param numStringsToGenerate
 * @param maxRecordsInRam
 */
@Test(dataProvider="String_Node_Str") public void testPositive(final String testName,final int numStringsToGenerate,final int maxRecordsInRam){
  final String[] strings=new String[numStringsToGenerate];
  int numStringsGenerated=0;
  final SortingCollection<String> sortingCollection=makeSortingCollection(maxRecordsInRam);
  for (  final String s : new RandomStringGenerator(numStringsToGenerate)) {
    sortingCollection.add(s);
    strings[numStringsGenerated++]=s;
  }
  Arrays.sort(strings,new StringComparator());
  Assert.assertEquals(tmpDirIsEmpty(),numStringsToGenerate <= maxRecordsInRam);
  sortingCollection.setDestructiveIteration(false);
  assertIteratorEqualsList(strings,sortingCollection.iterator());
  assertIteratorEqualsList(strings,sortingCollection.iterator());
  sortingCollection.cleanup();
  Assert.assertEquals(tmpDir().list().length,0);
}
Program: 30513
Project: 30513
Buggy source:
@AfterTest void tearDown(){
  System.err.println("String_Node_Str" + tmpDir);
  if (tmpDir.exists()) {
    for (    final File f : tmpDir.listFiles()) {
      f.delete();
    }
    tmpDir.delete();
  }
}

Fixed version (ground truth):
@AfterMethod void tearDown(){
  resetTmpDir();
}
Program: 30514
Project: 30514
Buggy source:
@BeforeTest void setup(){
  if (tmpDir.exists()) {
    for (    final File f : tmpDir.listFiles()) {
      f.delete();
    }
  }
  tmpDir.mkdirs();
}

Fixed version (ground truth):
@BeforeMethod void setup(){
  resetTmpDir();
}
Program: 30516
Project: 30516
Buggy source:
private List<SAMRecord> createRecords(int count) throws Exception {
  List<SAMRecord> list=new ArrayList<SAMRecord>(count);
  final SAMRecordSetBuilder builder=new SAMRecordSetBuilder();
  if (builder.getHeader().getReadGroups().isEmpty()) {
    throw new Exception("String_Node_Str");
  }
  int posInRef=1;
  for (int i=0; i < count / 2; i++)   builder.addPair(Integer.toString(i),0,posInRef+=1,posInRef+=3);
  list.addAll(builder.getRecords());
  Collections.sort(list,new SAMRecordCoordinateComparator());
  return list;
}

Fixed version (ground truth):
private List<SAMRecord> createRecords(int count) throws Exception {
  List<SAMRecord> list=new ArrayList<SAMRecord>(count);
  final SAMRecordSetBuilder builder=new SAMRecordSetBuilder();
  if (builder.getHeader().getReadGroups().isEmpty()) {
    throw new Exception("String_Node_Str");
  }
  int posInRef=1;
  for (int i=0; i < count / 2; i++) {
    builder.addPair(Integer.toString(i),0,posInRef+=1,posInRef+=3);
  }
  list.addAll(builder.getRecords());
  Collections.sort(list,new SAMRecordCoordinateComparator());
  return list;
}
Program: 30517
Project: 30517
Buggy source:
/** 
 * Remove all options from the set of <code>Options</code> for the <code>VariantContextWriterBuilder</code>.
 * @return this VariantContextWriterBuilder
 */
public VariantContextWriterBuilder clearOptions(){
  this.options=NO_OPTIONS;
  return this;
}

Fixed version (ground truth):
/** 
 * Remove all options from the set of <code>Options</code> for the <code>VariantContextWriterBuilder</code>.
 * @return this VariantContextWriterBuilder
 */
public VariantContextWriterBuilder clearOptions(){
  this.options=NO_OPTIONS.clone();
  return this;
}
Program: 30518
Project: 30518
Buggy source:
protected AbstractBAMFileIndex(final File file,final SAMSequenceDictionary dictionary,final boolean useMemoryMapping){
  mBamDictionary=dictionary;
  mIndexBuffer=(useMemoryMapping ? new MemoryMappedFileBuffer(file) : new RandomAccessFileBuffer(file));
  seek(0);
  final byte[] buffer=new byte[4];
  readBytes(buffer);
  if (!Arrays.equals(buffer,BAMFileConstants.BAM_INDEX_MAGIC)) {
    throw new RuntimeIOException("String_Node_Str" + file + "String_Node_Str"+ new String(buffer));
  }
  sequenceIndexes=new int[readInteger() + 1];
  Arrays.fill(sequenceIndexes,-1);
}

Fixed version (ground truth):
protected AbstractBAMFileIndex(final File file,final SAMSequenceDictionary dictionary,final boolean useMemoryMapping){
  mBamDictionary=dictionary;
  mIndexBuffer=(useMemoryMapping ? new MemoryMappedFileBuffer(file) : new RandomAccessFileBuffer(file));
  verifyBAMMagicNumber(file.getName());
  sequenceIndexes=new int[readInteger() + 1];
  Arrays.fill(sequenceIndexes,-1);
}
Program: 30519
Project: 30519
Buggy source:
public CRAMIterator(final SeekableStream seekableStream,final ReferenceSource referenceSource,final long[] coordinates) throws IOException {
  this.countingInputStream=new CountingInputStream(seekableStream);
  this.referenceSource=referenceSource;
  final CramSpanContainerIterator containerIterator=CramSpanContainerIterator.fromFileSpan(seekableStream,coordinates);
  cramHeader=containerIterator.getCramHeader();
  this.containerIterator=containerIterator;
  firstContainerOffset=containerIterator.getFirstContainerOffset();
  records=new ArrayList<SAMRecord>(10000);
  normalizer=new CramNormalizer(cramHeader.getSamFileHeader(),referenceSource);
  parser=new ContainerParser(cramHeader.getSamFileHeader());
}

Fixed version (ground truth):
public CRAMIterator(final SeekableStream seekableStream,final ReferenceSource referenceSource,final long[] coordinates) throws IOException {
  if (null == referenceSource) {
    throw new CRAMException("String_Node_Str");
  }
  this.countingInputStream=new CountingInputStream(seekableStream);
  this.referenceSource=referenceSource;
  final CramSpanContainerIterator containerIterator=CramSpanContainerIterator.fromFileSpan(seekableStream,coordinates);
  cramHeader=containerIterator.getCramHeader();
  this.containerIterator=containerIterator;
  firstContainerOffset=containerIterator.getFirstContainerOffset();
  records=new ArrayList<SAMRecord>(10000);
  normalizer=new CramNormalizer(cramHeader.getSamFileHeader(),referenceSource);
  parser=new ContainerParser(cramHeader.getSamFileHeader());
}
Program: 30520
Project: 30520
Buggy source:
@Override public int compareTo(final CRAIEntry o){
  if (o == null) {
    return 1;
  }
  if (sequenceId != o.sequenceId) {
    return o.sequenceId - sequenceId;
  }
  if (alignmentStart != o.alignmentStart) {
    return alignmentStart - o.alignmentStart;
  }
  return (int)(containerStartOffset - o.containerStartOffset);
}

Fixed version (ground truth):
@Override public int compareTo(final CRAIEntry o){
  if (o == null) {
    return 1;
  }
  if (sequenceId != o.sequenceId) {
    return sequenceId - o.sequenceId;
  }
  if (alignmentStart != o.alignmentStart) {
    return alignmentStart - o.alignmentStart;
  }
  return (int)(containerStartOffset - o.containerStartOffset);
}
Program: 30521
Project: 30521
Buggy source:
@Test(dataProvider="String_Node_Str") public void CRAMIndexTest(final String inputFile){
  final File input=new File(TEST_DATA_DIR,inputFile);
  final SamReader reader=SamReaderFactory.makeDefault().open(input);
  Assert.assertTrue(reader.hasIndex());
  CloserUtil.close(reader);
}

Fixed version (ground truth):
@Test(dataProvider="String_Node_Str") public void CRAMIndexTest(final String inputFile,final String referenceFile,QueryInterval queryInterval,String expectedReadName){
  final File input=new File(TEST_DATA_DIR,inputFile);
  final File reference=new File(TEST_DATA_DIR,referenceFile);
  final SamReader reader=SamReaderFactory.makeDefault().referenceSequence(reference).open(input);
  Assert.assertTrue(reader.hasIndex());
  final CloseableIterator<SAMRecord> iterator=reader.query(new QueryInterval[]{queryInterval},false);
  Assert.assertTrue(iterator.hasNext());
  SAMRecord r1=iterator.next();
  Assert.assertEquals(r1.getReadName(),expectedReadName);
  CloserUtil.close(reader);
}
Program: 30522
Project: 30522
Buggy source:
@DataProvider(name="String_Node_Str") public Object[][] CRAMIndexTestData(){
  final Object[][] testFiles=new Object[][]{{"String_Node_Str"}};
  return testFiles;
}

Fixed version (ground truth):
@DataProvider(name="String_Node_Str") public Object[][] CRAMIndexTestData(){
  final Object[][] testFiles=new Object[][]{{"String_Node_Str","String_Node_Str",new QueryInterval(0,12,13),"String_Node_Str"},{"String_Node_Str","String_Node_Str",new QueryInterval(3,700,0),"String_Node_Str"},{"String_Node_Str","String_Node_Str",new QueryInterval(2,350,0),"String_Node_Str"}};
  return testFiles;
}
Program: 30523
Project: 30523
Buggy source:
@DataProvider(name="String_Node_Str") public Object[][] CRAMNoIndexTestData(){
  final Object[][] testFiles=new Object[][]{{"String_Node_Str"}};
  return testFiles;
}

Fixed version (ground truth):
@DataProvider(name="String_Node_Str") public Object[][] CRAMNoIndexTestData(){
  final Object[][] testFiles=new Object[][]{{"String_Node_Str","String_Node_Str"}};
  return testFiles;
}
Program: 30524
Project: 30524
Buggy source:
@Test(dataProvider="String_Node_Str") public void CRAMNoIndexTest(final String inputFile){
  final File input=new File(TEST_DATA_DIR,inputFile);
  final SamReader reader=SamReaderFactory.makeDefault().open(input);
  Assert.assertFalse(reader.hasIndex());
  CloserUtil.close(reader);
}

Fixed version (ground truth):
@Test(dataProvider="String_Node_Str") public void CRAMNoIndexTest(final String inputFile,final String referenceFile){
  final File input=new File(TEST_DATA_DIR,inputFile);
  final File reference=new File(TEST_DATA_DIR,referenceFile);
  final SamReader reader=SamReaderFactory.makeDefault().referenceSequence(reference).open(input);
  Assert.assertFalse(reader.hasIndex());
  CloserUtil.close(reader);
}
Program: 30525
Project: 30525
Buggy source:
/** 
 * Read bases from input
 * @param knownLength For performance:: -1 if length is not known, otherwise the length of the sequence.
 * @return ASCII bases for sequence
 */
private byte[] readSequence(final int knownLength){
  byte[] bases=(knownLength == -1) ? basesBuffer : new byte[knownLength];
  int sequenceLength=0;
  while (!in.eof()) {
    final boolean sawEoln=in.skipNewlines();
    if (in.eof()) {
      break;
    }
    if (sawEoln && in.peekByte() == '>') {
      break;
    }
    sequenceLength+=in.readToEndOfOutputBufferOrEoln(bases,sequenceLength);
    while (sequenceLength > 0 && Character.isWhitespace(StringUtil.byteToChar(bases[sequenceLength - 1]))) {
      --sequenceLength;
    }
    if (sequenceLength == knownLength) {
      break;
    }
    if (sequenceLength == bases.length) {
      final byte[] tmp=new byte[bases.length * 2];
      System.arraycopy(bases,0,tmp,0,sequenceLength);
      bases=tmp;
    }
  }
  if (sequenceLength != bases.length || bases == basesBuffer) {
    final byte[] tmp=new byte[sequenceLength];
    System.arraycopy(bases,0,tmp,0,sequenceLength);
    bases=tmp;
  }
  return bases;
}

Fixed version (ground truth):
/** 
 * Read bases from input
 * @param knownLength For performance:: -1 if length is not known, otherwise the length of the sequence.
 * @return ASCII bases for sequence
 */
private byte[] readSequence(final int knownLength){
  byte[] bases=(knownLength == -1) ? basesBuffer : new byte[knownLength];
  int sequenceLength=0;
  while (!in.eof()) {
    final boolean sawEoln=in.skipNewlines();
    if (in.eof()) {
      break;
    }
    if (sawEoln && in.peekByte() == '>') {
      break;
    }
    sequenceLength+=in.readToEndOfOutputBufferOrEoln(bases,sequenceLength);
    while (sequenceLength > 0 && Character.isWhitespace(StringUtil.byteToChar(bases[sequenceLength - 1]))) {
      --sequenceLength;
    }
    if (sequenceLength == knownLength) {
      skipToEoln();
      break;
    }
    if (sequenceLength == bases.length) {
      final byte[] tmp=new byte[bases.length * 2];
      System.arraycopy(bases,0,tmp,0,sequenceLength);
      bases=tmp;
    }
  }
  if (sequenceLength != bases.length || bases == basesBuffer) {
    final byte[] tmp=new byte[sequenceLength];
    System.arraycopy(bases,0,tmp,0,sequenceLength);
    bases=tmp;
  }
  return bases;
}