nus-yam/ex-repair huggingface dataset:
Program: 22624
Project: 22624
Buggy source:
public char charAt(int index){
  int ix=index;
  if (ix >= data.length) {
    throw new StringIndexOutOfBoundsException("String_Node_Str" + index + "String_Node_Str"+ length());
  }
  return (char)(data[ix] & 0xff);
}

Fixed version (ground truth):
public char charAt(int index){
  System.err.println("String_Node_Str");
  int ix=index;
  if (ix >= data.length) {
    throw new StringIndexOutOfBoundsException("String_Node_Str" + index + "String_Node_Str"+ length());
  }
  return (char)(data[ix] & 0xff);
}
Program: 22625
Project: 22625
Buggy source:
@Override public CharSequence subSequence(int start,int end){
  if (start < 0 || end > (this.length()) || (end - start) < 0) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start];
  System.arraycopy(buffer,start,newdata,0,end - start);
  return new ReplazableString(newdata);
}

Fixed version (ground truth):
@Override public CharSequence subSequence(int start,int end){
  System.err.println("String_Node_Str");
  if (start < 0 || end > (this.length()) || (end - start) < 0) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start];
  System.arraycopy(buffer,start,newdata,0,end - start);
  return new ReplazableString(newdata);
}
Program: 22626
Project: 22626
Buggy source:
@Override public int compareTo(ReplazableString other){
  int n=Math.min(used,other.used);
  int k=0;
  while (k < n) {
    byte c1=this.buffer[k];
    byte c2=other.buffer[k];
    if (c1 != c2) {
      return c1 - c2;
    }
    k++;
  }
  return used - other.used;
}

Fixed version (ground truth):
@Override public int compareTo(ReplazableString other){
  int n=Math.min(used,other.used);
  int k=0;
  while (k < n) {
    int c1=this.buffer[k] & 0xFF;
    int c2=other.buffer[k] & 0xFF;
    if (c1 != c2) {
      return c1 - c2;
    }
    k++;
  }
  return used - other.used;
}
Program: 22627
Project: 22627
Buggy source:
@Override public char charAt(int index){
  return (char)buffer[index];
}

Fixed version (ground truth):
@Override public char charAt(int index){
  System.err.println("String_Node_Str");
  return (char)buffer[index];
}
Program: 22628
Project: 22628
Buggy source:
public void replace2(InputStream in,int pos) throws IOException {
  used=pos;
  while (true) {
    int value=in.read();
    if (value == -1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    if (value == 0) {
      break;
    }
    if (pos >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[pos++]=(byte)(value & 0xFF);
    used++;
  }
}

Fixed version (ground truth):
public void replace2(InputStream in,int pos) throws IOException {
  used=pos;
  while (true) {
    int value=in.read();
    if (value == -1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    if (value == 0) {
      break;
    }
    if (used >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=(byte)(value & 0xFF);
  }
}
Program: 22629
Project: 22629
Buggy source:
public void replace(ByteBuffer in,int pos) throws IOException {
  used=pos;
  int n=in.capacity() - in.position();
  while (n-- != 0) {
    byte value=in.get();
    if (value == 0) {
      return;
    }
    if (pos >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=value;
  }
  throw new IllegalArgumentException("String_Node_Str");
}

Fixed version (ground truth):
public void replace(ByteBuffer in,int pos) throws IOException {
  used=pos;
  int n=in.capacity() - in.position();
  while (n-- != 0) {
    byte value=in.get();
    if (value == 0) {
      return;
    }
    if (used >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=value;
  }
  throw new IllegalArgumentException("String_Node_Str");
}
Program: 22630
Project: 22630
Buggy source:
public void replace2(InputStream in,int pos) throws IOException {
  used=pos;
  while (true) {
    int value=in.read();
    if (value == -1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    if (value == 0) {
      break;
    }
    if (pos >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[pos++]=(byte)(value & 0xFF);
    used++;
  }
}

Fixed version (ground truth):
public void replace2(InputStream in,int pos) throws IOException {
  used=pos;
  while (true) {
    int value=in.read();
    if (value == -1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    if (value == 0) {
      break;
    }
    if (used >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=(byte)(value & 0xFF);
  }
}
Program: 22631
Project: 22631
Buggy source:
public void replace(ByteBuffer in,int pos) throws IOException {
  used=pos;
  int n=in.capacity() - in.position();
  while (n-- != 0) {
    byte value=in.get();
    if (value == 0) {
      return;
    }
    if (pos >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=value;
  }
  throw new IllegalArgumentException("String_Node_Str");
}

Fixed version (ground truth):
public void replace(ByteBuffer in,int pos) throws IOException {
  used=pos;
  int n=in.capacity() - in.position();
  while (n-- != 0) {
    byte value=in.get();
    if (value == 0) {
      return;
    }
    if (used >= buffer.length) {
      buffer=Arrays.copyOf(buffer,buffer.length * 2);
    }
    buffer[used++]=value;
  }
  throw new IllegalArgumentException("String_Node_Str");
}
Program: 22632
Project: 22632
Buggy source:
@Override public CharSequence next(){
  if (!buffer.hasRemaining()) {
    buffer=buffers[bytebufferIndex].duplicate();
    buffer.rewind();
  }
  try {
    if ((id % blocksize) == 0) {
      tempString.replace(buffer,0);
    }
 else {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
    }
    id++;
    return tempString.toString();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@Override public CharSequence next(){
  if (!buffer.hasRemaining()) {
    buffer=buffers[++bytebufferIndex].duplicate();
    buffer.rewind();
  }
  try {
    if ((id % blocksize) == 0) {
      tempString.replace(buffer,0);
    }
 else {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
    }
    id++;
    return tempString.toString();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
Program: 22633
Project: 22633
Buggy source:
@Override public Iterator<CharSequence> getSortedEntries(){
  return new Iterator<CharSequence>(){
    int id=0;
    ReplazableString tempString=new ReplazableString();
    int bytebufferIndex=0;
    ByteBuffer buffer=buffers[0].duplicate();
    @Override public boolean hasNext(){
      return id < getNumberOfElements();
    }
    @Override public CharSequence next(){
      if (!buffer.hasRemaining()) {
        buffer=buffers[bytebufferIndex].duplicate();
        buffer.rewind();
      }
      try {
        if ((id % blocksize) == 0) {
          tempString.replace(buffer,0);
        }
 else {
          long delta=VByte.decode(buffer);
          tempString.replace(buffer,(int)delta);
        }
        id++;
        return tempString.toString();
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
  }
;
}

Fixed version (ground truth):
@Override public Iterator<CharSequence> getSortedEntries(){
  return new Iterator<CharSequence>(){
    int id=0;
    ReplazableString tempString=new ReplazableString();
    int bytebufferIndex=0;
    ByteBuffer buffer=buffers[0].duplicate();
    @Override public boolean hasNext(){
      return id < getNumberOfElements();
    }
    @Override public CharSequence next(){
      if (!buffer.hasRemaining()) {
        buffer=buffers[++bytebufferIndex].duplicate();
        buffer.rewind();
      }
      try {
        if ((id % blocksize) == 0) {
          tempString.replace(buffer,0);
        }
 else {
          long delta=VByte.decode(buffer);
          tempString.replace(buffer,(int)delta);
        }
        id++;
        return tempString.toString();
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
  }
;
}
Program: 22635
Project: 22635
Buggy source:
@Override public char charAt(int index){
  return (char)buffer[index];
}

Fixed version (ground truth):
@Override public char charAt(int index){
  return (char)(buffer[index] & 0xff);
}
Program: 22636
Project: 22636
Buggy source:
@Override public TripleID next(){
  if (!goingUp) {
    goingUp=true;
    if (hasPreviousTriples) {
      doFetchNext();
    }
    doFetchNext();
  }
  returnTriple=nextTriple;
  doFetchNext();
  return returnTriple;
}

Fixed version (ground truth):
@Override public TripleID next(){
  if (!goingUp) {
    goingUp=true;
    if (hasPreviousTriples) {
      doFetchNext();
    }
    doFetchNext();
  }
  returnTriple.assign(nextTriple);
  doFetchNext();
  return returnTriple;
}
Program: 22637
Project: 22637
Buggy source:
@Override public TripleID previous(){
  if (goingUp) {
    goingUp=false;
    if (hasMoreTriples) {
      doFetchPrevious();
    }
    doFetchPrevious();
  }
  returnTriple=previousTriple;
  doFetchPrevious();
  return returnTriple;
}

Fixed version (ground truth):
@Override public TripleID previous(){
  if (goingUp) {
    goingUp=false;
    if (hasMoreTriples) {
      doFetchPrevious();
    }
    doFetchPrevious();
  }
  returnTriple.assign(previousTriple);
  doFetchPrevious();
  return returnTriple;
}
Program: 22638
Project: 22638
Buggy source:
private void doFetchPrevious(){
  hasPreviousTriples=false;
  while (iterator.hasPrevious()) {
    TripleID previous=iterator.previous();
    if (previous.match(pattern)) {
      hasPreviousTriples=true;
      hasMoreTriples=true;
      previousTriple=previous;
      break;
    }
  }
}

Fixed version (ground truth):
private void doFetchPrevious(){
  hasPreviousTriples=false;
  while (iterator.hasPrevious()) {
    TripleID previous=iterator.previous();
    if (previous.match(pattern)) {
      hasPreviousTriples=true;
      hasMoreTriples=true;
      previousTriple.assign(previous);
      break;
    }
  }
}
Program: 22639
Project: 22639
Buggy source:
public SequentialSearchIteratorTripleID(TripleID pattern,IteratorTripleID other){
  this.pattern=pattern;
  this.iterator=other;
  hasPreviousTriples=false;
  goingUp=true;
  nextTriple=new TripleID();
  doFetchNext();
}

Fixed version (ground truth):
public SequentialSearchIteratorTripleID(TripleID pattern,IteratorTripleID other){
  this.pattern=pattern;
  this.iterator=other;
  hasPreviousTriples=false;
  goingUp=true;
  nextTriple=new TripleID();
  returnTriple=new TripleID();
  doFetchNext();
}
Program: 22640
Project: 22640
Buggy source:
@Override public void load(InputStream input,ProgressListener listener) throws IOException {
  CRCInputStream in=new CRCInputStream(input,new CRC8());
  int type=in.read();
  if (type != TYPE_INDEX) {
    throw new IllegalFormatException("String_Node_Str");
  }
  numstrings=(int)VByte.decode(in);
  this.size=VByte.decode(in);
  blocksize=(int)VByte.decode(in);
  if (!in.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
  blocks=new SequenceLog64();
  blocks.load(input,listener);
  in.setCRC(new CRC32());
  int block=0;
  int buffer=0;
  long bytePos=0;
  long numBlocks=blocks.getNumberOfElements();
  long numBuffers=1 + numBlocks / BLOCK_PER_BUFFER;
  data=new byte[(int)numBuffers][];
  posFirst=new long[(int)numBuffers];
  while (block < numBlocks - 1) {
    int nextBlock=(int)Math.min(numBlocks - 1,block + BLOCK_PER_BUFFER);
    long nextBytePos=blocks.get(nextBlock);
    data[buffer]=new byte[(int)(nextBytePos - bytePos)];
    int read=in.read(data[buffer]);
    if (read != data[buffer].length) {
      throw new IOException("String_Node_Str");
    }
    posFirst[buffer]=bytePos;
    bytePos=nextBytePos;
    block+=BLOCK_PER_BUFFER;
    buffer++;
  }
  if (!in.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void load(InputStream input,ProgressListener listener) throws IOException {
  CRCInputStream in=new CRCInputStream(input,new CRC8());
  int type=in.read();
  if (type != TYPE_INDEX) {
    throw new IllegalFormatException("String_Node_Str");
  }
  numstrings=(int)VByte.decode(in);
  this.size=VByte.decode(in);
  blocksize=(int)VByte.decode(in);
  if (!in.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
  blocks=new SequenceLog64();
  blocks.load(input,listener);
  in.setCRC(new CRC32());
  int block=0;
  int buffer=0;
  long bytePos=0;
  long numBlocks=blocks.getNumberOfElements();
  long numBuffers=1 + numBlocks / BLOCK_PER_BUFFER;
  data=new byte[(int)numBuffers][];
  posFirst=new long[(int)numBuffers];
  while (block < numBlocks - 1) {
    int nextBlock=(int)Math.min(numBlocks - 1,block + BLOCK_PER_BUFFER);
    long nextBytePos=blocks.get(nextBlock);
    data[buffer]=IOUtil.readBuffer(in,(int)(nextBytePos - bytePos),null);
    posFirst[buffer]=bytePos;
    bytePos=nextBytePos;
    block+=BLOCK_PER_BUFFER;
    buffer++;
  }
  if (!in.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
}
Program: 22641
Project: 22641
Buggy source:
@Override public int read(byte[] b,int off,int len) throws IOException {
  int ret=in.read(b,off,len);
  crc.update(b,off,len);
  return ret;
}

Fixed version (ground truth):
@Override public int read(byte[] b,int off,int len) throws IOException {
  int ret=in.read(b,off,len);
  crc.update(b,off,ret);
  return ret;
}
Program: 22642
Project: 22642
Buggy source:
/** 
 * Convert int to byte array, little endian
 */
public static byte[] intToByteArray(int value){
  byte writeBuffer[]=new byte[4];
  writeBuffer[0]=(byte)(value & 0xFF);
  writeBuffer[1]=(byte)((value >> 8) & 0xFF);
  writeBuffer[2]=(byte)((value >> 16) & 0xFF);
  writeBuffer[3]=(byte)((value >> 24) & 0xFF);
  return Arrays.copyOfRange(writeBuffer,0,4);
}

Fixed version (ground truth):
/** 
 * Convert int to byte array, little endian
 */
public static byte[] intToByteArray(int value){
  byte writeBuffer[]=new byte[4];
  writeBuffer[0]=(byte)(value & 0xFF);
  writeBuffer[1]=(byte)((value >> 8) & 0xFF);
  writeBuffer[2]=(byte)((value >> 16) & 0xFF);
  writeBuffer[3]=(byte)((value >> 24) & 0xFF);
  return writeBuffer;
}
Program: 22643
Project: 22643
Buggy source:
/** 
 * Read long, little endian. Warning: Dont use concurrently!!
 * @param input
 * @return
 * @throws IOException
 */
public static final long readLong(InputStream input) throws IOException {
  int n=0;
  while (n < 8) {
    int count=input.read(readBuffer,0,8);
    if (count < 0)     throw new EOFException();
    n+=count;
  }
  return (((long)readBuffer[7] << 56) + ((long)(readBuffer[6] & 255) << 48) + ((long)(readBuffer[5] & 255) << 40)+ ((long)(readBuffer[4] & 255) << 32)+ ((long)(readBuffer[3] & 255) << 24)+ ((readBuffer[2] & 255) << 16)+ ((readBuffer[1] & 255) << 8)+ ((readBuffer[0] & 255)));
}

Fixed version (ground truth):
/** 
 * Read long, little endian.
 * @param input
 * @return
 * @throws IOException
 */
public static final long readLong(InputStream input) throws IOException {
  int n=0;
  byte readBuffer[]=new byte[8];
  while (n < 8) {
    int count=input.read(readBuffer,n,8 - n);
    if (count < 0)     throw new EOFException();
    n+=count;
  }
  return (((long)readBuffer[7] << 56) + ((long)(readBuffer[6] & 255) << 48) + ((long)(readBuffer[5] & 255) << 40)+ ((long)(readBuffer[4] & 255) << 32)+ ((long)(readBuffer[3] & 255) << 24)+ ((readBuffer[2] & 255) << 16)+ ((readBuffer[1] & 255) << 8)+ ((readBuffer[0] & 255)));
}
Program: 22644
Project: 22644
Buggy source:
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    int cmp=ByteStringUtil.strcmp(str,text,(int)blocks.get(mid));
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}

Fixed version (ground truth):
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  int max=high;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    int cmp;
    if (mid == max) {
      cmp=-1;
    }
 else {
      int pos=(int)blocks.get(mid);
      cmp=ByteStringUtil.strcmp(str,text,pos);
    }
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}
Program: 22645
Project: 22645
Buggy source:
/** 
 * Locate the block of a string doing binary search.
 */
private int locateBlock(CharSequence str){
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    int cmp=ByteStringUtil.strcmp(str,data[mid / BLOCK_PER_BUFFER],(int)(blocks.get(mid) - posFirst[mid / BLOCK_PER_BUFFER]));
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}

Fixed version (ground truth):
/** 
 * Locate the block of a string doing binary search.
 */
private int locateBlock(CharSequence str){
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  int max=high;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    int cmp;
    if (max == high) {
      cmp=-1;
    }
 else {
      cmp=ByteStringUtil.strcmp(str,data[mid / BLOCK_PER_BUFFER],(int)(blocks.get(mid) - posFirst[mid / BLOCK_PER_BUFFER]));
    }
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}
Program: 22646
Project: 22646
Buggy source:
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  while (low <= high) {
    int mid=low + (high - low) / 2;
    ByteBuffer buffer=buffers[mid / BLOCKS_PER_BYTEBUFFER];
    int cmp=ByteStringUtil.strcmp(str,buffer,(int)(blocks.get(mid) - posFirst[mid / BLOCKS_PER_BYTEBUFFER]));
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}

Fixed version (ground truth):
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  int max=high;
  while (low <= high) {
    int mid=low + (high - low) / 2;
    int cmp;
    if (mid == max) {
      cmp=-1;
    }
 else {
      ByteBuffer buffer=buffers[mid / BLOCKS_PER_BYTEBUFFER];
      cmp=ByteStringUtil.strcmp(str,buffer,(int)(blocks.get(mid) - posFirst[mid / BLOCKS_PER_BYTEBUFFER]));
    }
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}
Program: 22647
Project: 22647
Buggy source:
public int locateInBlock(int block,CharSequence str){
  if (block >= blocks.getNumberOfElements()) {
    return 0;
  }
  ReplazableString tempString=new ReplazableString();
  int idInBlock=0;
  int cshared=0;
  ByteBuffer buffer=buffers[block / BLOCKS_PER_BYTEBUFFER].duplicate();
  buffer.position((int)(blocks.get(block) - posFirst[block / BLOCKS_PER_BYTEBUFFER]));
  try {
    if (!buffer.hasRemaining()) {
      return 0;
    }
    tempString.replace(buffer,0);
    idInBlock++;
    while ((idInBlock < blocksize) && buffer.hasRemaining()) {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
      if (delta >= cshared) {
        cshared+=ByteStringUtil.longestCommonPrefix(tempString,str,cshared);
        if ((cshared == str.length()) && (tempString.length() == str.length())) {
          break;
        }
      }
 else {
        idInBlock=0;
        break;
      }
      idInBlock++;
    }
    if (!buffer.hasRemaining() || idInBlock == blocksize) {
      idInBlock=0;
    }
    return idInBlock;
  }
 catch (  IOException e) {
    e.printStackTrace();
    return 0;
  }
}

Fixed version (ground truth):
public int locateInBlock(int block,CharSequence str){
  if (block >= blocks.getNumberOfElements()) {
    return 0;
  }
  ReplazableString tempString=new ReplazableString();
  int idInBlock=0;
  int cshared=0;
  ByteBuffer buffer=buffers[block / BLOCKS_PER_BYTEBUFFER].duplicate();
  buffer.position((int)(blocks.get(block) - posFirst[block / BLOCKS_PER_BYTEBUFFER]));
  try {
    if (!buffer.hasRemaining()) {
      return 0;
    }
    tempString.replace(buffer,0);
    idInBlock++;
    while ((idInBlock < blocksize) && buffer.hasRemaining()) {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
      if (delta >= cshared) {
        cshared+=ByteStringUtil.longestCommonPrefix(tempString,str,cshared);
        if ((cshared == str.length()) && (tempString.length() == str.length())) {
          return idInBlock;
        }
      }
 else {
        return 0;
      }
      idInBlock++;
    }
    return 0;
  }
 catch (  IOException e) {
    e.printStackTrace();
    return 0;
  }
}
Program: 22648
Project: 22648
Buggy source:
@Override public void processTriple(TripleString triple,long pos){
  this.insert(triple.getSubject(),triple.getPredicate(),triple.getObject());
}

Fixed version (ground truth):
@Override public void processTriple(TripleString triple,long pos){
  triples.add(new TripleString(triple));
}
Program: 22649
Project: 22649
Buggy source:
public static final int strcmp(CharSequence str,ByteBuffer buffer,int offset){
  byte[] buf=null;
  int len;
  if (str instanceof CompactString) {
    buf=((CompactString)str).getData();
    len=buf.length;
  }
 else   if (str instanceof String) {
    buf=((String)str).getBytes(ByteStringUtil.STRING_ENCODING);
    len=buf.length;
  }
 else   if (str instanceof ReplazableString) {
    buf=((ReplazableString)str).buffer;
    len=((ReplazableString)str).used;
  }
 else {
    throw new NotImplementedException();
  }
  int i=0;
  int n=Math.min(len,buffer.capacity() - offset);
  while (i < n) {
    byte v1=buf[i];
    byte v2=buffer.get(offset + i);
    if (v1 != v2) {
      return v1 - v2;
    }
    if (v1 == 0) {
      return 0;
    }
    i++;
  }
  if (buffer.capacity() - offset - i > 0) {
    byte v=buffer.get(offset + i);
    if (v == 0) {
      return 0;
    }
 else {
      return -1;
    }
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}

Fixed version (ground truth):
public static final int strcmp(CharSequence str,ByteBuffer buffer,int offset){
  byte[] buf=null;
  int len;
  if (str instanceof CompactString) {
    buf=((CompactString)str).getData();
    len=buf.length;
  }
 else   if (str instanceof String) {
    buf=((String)str).getBytes(ByteStringUtil.STRING_ENCODING);
    len=buf.length;
  }
 else   if (str instanceof ReplazableString) {
    buf=((ReplazableString)str).buffer;
    len=((ReplazableString)str).used;
  }
 else {
    throw new NotImplementedException();
  }
  int i=0;
  int n=Math.min(len,buffer.capacity() - offset);
  while (i < n) {
    int v1=buf[i] & 0xFF;
    int v2=buffer.get(offset + i) & 0xFF;
    if (v1 != v2) {
      return v1 - v2;
    }
    if (v1 == 0) {
      return 0;
    }
    i++;
  }
  if (buffer.capacity() - offset - i > 0) {
    byte v=buffer.get(offset + i);
    if (v == 0) {
      return 0;
    }
 else {
      return -1;
    }
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}
Program: 22650
Project: 22650
Buggy source:
@Override public void insert(CharSequence subject,CharSequence predicate,long object){
  triples.add(new TripleString(subject,predicate,'"' + Long.toString(object) + '"'));
}

Fixed version (ground truth):
@Override public void insert(CharSequence subject,CharSequence predicate,long object){
  triples.add(new TripleString(HeaderUtil.cleanURI(subject),HeaderUtil.cleanURI(predicate),'"' + Long.toString(object) + '"'));
}
Program: 22652
Project: 22652
Buggy source:
@Override public void loadFromHDT(String hdtFileName,ProgressListener listener) throws IOException {
  InputStream in;
  if (hdtFileName.endsWith("String_Node_Str")) {
    in=new GZIPInputStream(new FileInputStream(hdtFileName));
  }
 else {
    in=new BufferedInputStream(new FileInputStream(hdtFileName));
  }
  loadFromHDT(in,listener);
  in.close();
  this.hdtFileName=hdtFileName;
}

Fixed version (ground truth):
@Override public void loadFromHDT(String hdtFileName,ProgressListener listener) throws IOException {
  InputStream in;
  if (hdtFileName.endsWith("String_Node_Str")) {
    in=new BufferedInputStream(new GZIPInputStream(new FileInputStream(hdtFileName)));
  }
 else {
    in=new BufferedInputStream(new FileInputStream(hdtFileName));
  }
  loadFromHDT(in,listener);
  in.close();
  this.hdtFileName=hdtFileName;
}
Program: 22653
Project: 22653
Buggy source:
public static final int strcmp(ByteBuffer a,ByteBuffer b){
  int n=a.position() + Math.min(a.remaining(),a.remaining());
  for (int i=a.position(), j=b.position(); i < n; i++, j++) {
    byte v1=a.get(i);
    byte v2=b.get(j);
    if (v1 == 0) {
      if (v2 == 0) {
        return 0;
      }
 else {
        return 1;
      }
    }
    if (v2 == 0) {
      if (v1 == 0) {
        return 0;
      }
 else {
        return -1;
      }
    }
    if (v1 == v2)     continue;
    if (v1 < v2)     return -1;
    return +1;
  }
  return a.remaining() - b.remaining();
}

Fixed version (ground truth):
public static final int strcmp(ByteBuffer a,int abase,ByteBuffer b,int bbase){
  int i=0;
  int n=Math.min(a.capacity() - abase,b.capacity() - bbase);
  while (i < n) {
    byte v1=a.get(abase + i);
    byte v2=b.get(bbase + i);
    if (v1 == 0) {
      if (v2 == 0) {
        return 0;
      }
 else {
        return -1;
      }
    }
    if (v2 == 0) {
      return +1;
    }
    if (v1 != v2) {
      if (v1 < v2) {
        return -1;
      }
 else {
        return +1;
      }
    }
    i++;
  }
  throw new IllegalArgumentException("String_Node_Str");
}
Program: 22654
Project: 22654
Buggy source:
public static int strlen(ByteBuffer pos){
  pos.mark();
  int len=0;
  while (pos.hasRemaining() && pos.get() != 0) {
    len++;
  }
  pos.reset();
  return len;
}

Fixed version (ground truth):
public static final int strlen(ByteBuffer buf,int base){
  int len=0;
  int n=buf.capacity() - base;
  while (len < n) {
    if (buf.get(base + len) == 0) {
      return len;
    }
    len++;
  }
  throw new IllegalArgumentException("String_Node_Str");
}
Program: 22655
Project: 22655
Buggy source:
public static String asString(ByteBuffer buff){
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  while (buff.hasRemaining()) {
    byte b=buff.get();
    if (b == 0) {
      break;
    }
    out.write(b);
  }
  return new String(out.toByteArray());
}

Fixed version (ground truth):
public static final String asString(ByteBuffer buff,int offset){
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  int i=0;
  int n=buff.capacity() - offset;
  while (i < n) {
    byte b=buff.get(offset + i);
    if (b == 0) {
      break;
    }
    out.write(b);
    i++;
  }
  return new String(out.toByteArray(),STRING_ENCODING);
}
Program: 22656
Project: 22656
Buggy source:
public static int longestCommonPrefix(CharSequence str1,CharSequence str2,int from){
  int len=Math.min(str1.length(),str2.length());
  int delta=from;
  while (delta < len && str1.charAt(delta) == str2.charAt(delta)) {
    delta++;
  }
  return delta - from;
}

Fixed version (ground truth):
public static final int longestCommonPrefix(CharSequence str1,CharSequence str2,int from){
  int len=Math.min(str1.length(),str2.length());
  int delta=from;
  while (delta < len && str1.charAt(delta) == str2.charAt(delta)) {
    delta++;
  }
  return delta - from;
}
Program: 22657
Project: 22657
Buggy source:
/** 
 * Add numbits of value to buffer at pos
 * @param buffer
 * @param pos Position in bits.
 * @param value Value to be added
 * @param numbits numbits of value to be added.
 */
public static void append(long[] buffer,long pos,long value,int numbits){
  final int W=64;
  int i=(int)(pos / W), j=(int)(pos % W);
  if (numbits > (W - j)) {
    buffer[i]|=value << j >>> j;
    buffer[i + 1]|=(value << (W - j - numbits));
  }
 else {
    buffer[i]|=(value << (W - j - numbits));
  }
}

Fixed version (ground truth):
public static final int append(OutputStream out,CharSequence str,int start) throws IOException {
  byte[] bytes;
  int len;
  if (str instanceof String) {
    bytes=((String)str).getBytes(ByteStringUtil.STRING_ENCODING);
    len=bytes.length;
  }
 else   if (str instanceof CompactString) {
    bytes=((CompactString)str).getData();
    len=bytes.length;
  }
 else   if (str instanceof ReplazableString) {
    bytes=((ReplazableString)str).getBuffer();
    len=((ReplazableString)str).used;
  }
 else {
    throw new NotImplementedException();
  }
  out.write(bytes,start,len - start);
  return len - start;
}
Program: 22658
Project: 22658
Buggy source:
@Override public int compare(CharSequence s1,CharSequence s2){
  if (s1 instanceof CompactString && s2 instanceof CompactString) {
    CompactString cs1=(CompactString)s1;
    CompactString cs2=(CompactString)s2;
    return cs1.compareTo(cs2);
  }
  int len1=s1.length();
  int len2=s2.length();
  int n=Math.min(len1,len2);
  int k=0;
  while (k < n) {
    char c1=s1.charAt(k);
    char c2=s2.charAt(k);
    if (c1 != c2) {
      return c1 - c2;
    }
    k++;
  }
  return len1 - len2;
}

Fixed version (ground truth):
@Override public int compare(CharSequence s1,CharSequence s2){
  if (s1 instanceof CompactString && s2 instanceof CompactString) {
    CompactString cs1=(CompactString)s1;
    CompactString cs2=(CompactString)s2;
    return cs1.compareTo(cs2);
  }
  int len1=s1.length();
  int len2=s2.length();
  int n=Math.min(len1,len2);
  int k=0;
  while (k < n) {
    char c1=s1.charAt(k);
    char c2=s2.charAt(k);
    if (c1 != c2) {
      return c2 - c1;
    }
    k++;
  }
  return len2 - len1;
}
Program: 22659
Project: 22659
Buggy source:
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    ByteBuffer buffer=cacheBuffers.get()[mid / BLOCKS_PER_BYTEBUFFER];
    buffer.position((int)(blocks.get(mid) - blocks.get(mid - mid % BLOCKS_PER_BYTEBUFFER)));
    int cmp=ByteStringUtil.strcmp(str,buffer);
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}

Fixed version (ground truth):
private int locateBlock(CharSequence str){
  if (blocks.getNumberOfElements() == 0) {
    return -1;
  }
  int low=0;
  int high=(int)blocks.getNumberOfElements() - 1;
  while (low <= high) {
    int mid=(low + high) >>> 1;
    ByteBuffer buffer=cacheBuffers.get()[mid / BLOCKS_PER_BYTEBUFFER];
    buffer.position((int)(blocks.get(mid) - posFirst[mid / BLOCKS_PER_BYTEBUFFER]));
    int cmp=ByteStringUtil.strcmp(str,buffer);
    if (cmp < 0) {
      high=mid - 1;
    }
 else     if (cmp > 0) {
      low=mid + 1;
    }
 else {
      return mid;
    }
  }
  return -(low + 1);
}
Program: 22660
Project: 22660
Buggy source:
public int locateInBlock(int block,CharSequence str){
  if (block >= blocks.getNumberOfElements()) {
    return 0;
  }
  ReplazableString tempString=new ReplazableString();
  int idInBlock=0;
  int cshared=0;
  ByteBuffer buffer=cacheBuffers.get()[block / BLOCKS_PER_BYTEBUFFER];
  buffer.position((int)(blocks.get(block) - blocks.get(block - block % BLOCKS_PER_BYTEBUFFER)));
  try {
    tempString.replace(buffer,0);
    idInBlock++;
    while ((idInBlock < blocksize) && buffer.hasRemaining()) {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
      if (delta >= cshared) {
        cshared+=ByteStringUtil.longestCommonPrefix(tempString,str,cshared);
        if ((cshared == str.length()) && (tempString.length() == str.length())) {
          break;
        }
      }
 else {
        idInBlock=0;
        break;
      }
      idInBlock++;
    }
    if (!buffer.hasRemaining() || idInBlock == blocksize) {
      idInBlock=0;
    }
    return idInBlock;
  }
 catch (  IOException e) {
    e.printStackTrace();
    return 0;
  }
}

Fixed version (ground truth):
public int locateInBlock(int block,CharSequence str){
  if (block >= blocks.getNumberOfElements()) {
    return 0;
  }
  ReplazableString tempString=new ReplazableString();
  int idInBlock=0;
  int cshared=0;
  ByteBuffer buffer=cacheBuffers.get()[block / BLOCKS_PER_BYTEBUFFER];
  buffer.position((int)(blocks.get(block) - posFirst[block / BLOCKS_PER_BYTEBUFFER]));
  try {
    if (!buffer.hasRemaining()) {
      return 0;
    }
    tempString.replace(buffer,0);
    idInBlock++;
    while ((idInBlock < blocksize) && buffer.hasRemaining()) {
      long delta=VByte.decode(buffer);
      tempString.replace(buffer,(int)delta);
      if (delta >= cshared) {
        cshared+=ByteStringUtil.longestCommonPrefix(tempString,str,cshared);
        if ((cshared == str.length()) && (tempString.length() == str.length())) {
          break;
        }
      }
 else {
        idInBlock=0;
        break;
      }
      idInBlock++;
    }
    if (!buffer.hasRemaining() || idInBlock == blocksize) {
      idInBlock=0;
    }
    return idInBlock;
  }
 catch (  IOException e) {
    e.printStackTrace();
    return 0;
  }
}
Program: 22661
Project: 22661
Buggy source:
public PFCDictionarySectionMap(CountInputStream input,File f) throws IOException {
  CRCInputStream crcin=new CRCInputStream(input,new CRC8());
  int type=crcin.read();
  if (type != TYPE_INDEX) {
    throw new IllegalFormatException("String_Node_Str");
  }
  numstrings=(int)VByte.decode(crcin);
  dataSize=VByte.decode(crcin);
  blocksize=(int)VByte.decode(crcin);
  if (!crcin.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
  blocks=SequenceFactory.createStream(input);
  blocks.load(input,null);
  long base=input.getTotalBytes();
  IOUtil.skip(crcin,dataSize + 4);
  ch=new FileInputStream(f).getChannel();
  int block=0;
  int buffer=0;
  long numBlocks=blocks.getNumberOfElements();
  long bytePos=0;
  buffers=new ByteBuffer[(int)(1 + numBlocks / BLOCKS_PER_BYTEBUFFER)];
  while (block < numBlocks - 1) {
    int nextBlock=(int)Math.min(numBlocks - 1,block + BLOCKS_PER_BYTEBUFFER);
    long nextBytePos=blocks.get(nextBlock);
    buffers[buffer]=ch.map(MapMode.READ_ONLY,base + bytePos,nextBytePos - bytePos);
    buffers[buffer].order(ByteOrder.LITTLE_ENDIAN);
    bytePos=nextBytePos;
    block+=BLOCKS_PER_BYTEBUFFER;
    buffer++;
  }
}

Fixed version (ground truth):
public PFCDictionarySectionMap(CountInputStream input,File f) throws IOException {
  CRCInputStream crcin=new CRCInputStream(input,new CRC8());
  int type=crcin.read();
  if (type != TYPE_INDEX) {
    throw new IllegalFormatException("String_Node_Str");
  }
  numstrings=(int)VByte.decode(crcin);
  dataSize=VByte.decode(crcin);
  blocksize=(int)VByte.decode(crcin);
  if (!crcin.readCRCAndCheck()) {
    throw new CRCException("String_Node_Str");
  }
  blocks=SequenceFactory.createStream(input);
  blocks.load(input,null);
  long base=input.getTotalBytes();
  IOUtil.skip(crcin,dataSize + 4);
  ch=new FileInputStream(f).getChannel();
  int block=0;
  int buffer=0;
  long numBlocks=blocks.getNumberOfElements();
  long bytePos=0;
  long numBuffers=1 + numBlocks / BLOCKS_PER_BYTEBUFFER;
  buffers=new ByteBuffer[(int)numBuffers];
  posFirst=new long[(int)numBuffers];
  while (block < numBlocks - 1) {
    int nextBlock=(int)Math.min(numBlocks - 1,block + BLOCKS_PER_BYTEBUFFER);
    long nextBytePos=blocks.get(nextBlock);
    buffers[buffer]=ch.map(MapMode.READ_ONLY,base + bytePos,nextBytePos - bytePos);
    buffers[buffer].order(ByteOrder.LITTLE_ENDIAN);
    posFirst[buffer]=bytePos;
    bytePos=nextBytePos;
    block+=BLOCKS_PER_BYTEBUFFER;
    buffer++;
  }
}
Program: 22662
Project: 22662
Buggy source:
@Override public int read(byte[] b,int off,int len) throws IOException {
  int value=super.read(b,off,len);
  if (value != -1) {
    partial+=value;
    total+=value;
  }
  return value;
}

Fixed version (ground truth):
@Override public int read(byte[] b,int off,int len) throws IOException {
  int value=in.read(b,off,len);
  if (value != -1) {
    partial+=value;
    total+=value;
  }
  return value;
}
Program: 22663
Project: 22663
Buggy source:
/** 
 * @param parent
 */
public CountInputStream(InputStream parent){
  super(parent);
  total=0;
  partial=0;
}

Fixed version (ground truth):
/** 
 * @param parent
 */
public CountInputStream(InputStream input){
  this.in=input;
  total=0;
  partial=0;
}
Program: 22664
Project: 22664
Buggy source:
ParserException(String message){
  super(message);
}

Fixed version (ground truth):
public ParserException(String message){
  super(message);
}
Program: 22665
Project: 22665
Buggy source:
/** 
 * Read from a line, where each component is separated by space.
 * @param line
 */
public void read(String line){
  int split, posa, posb;
  this.clear();
  posa=0;
  posb=split=line.indexOf(' ',posa);
  if (posb == -1)   return;
  if (line.charAt(posa) == '<')   posa++;
  if (line.charAt(posb - 1) == '>')   posb--;
  this.setSubject(line.substring(posa,posb));
  posa=split + 1;
  posb=split=line.indexOf(' ',posa);
  if (posb == -1)   return;
  if (line.charAt(posa) == '<')   posa++;
  if (posb > posa && line.charAt(posb - 1) == '>')   posb--;
  this.setPredicate(line.substring(posa,posb));
  posa=split + 1;
  posb=line.length();
  if (line.charAt(posb - 1) == '.')   posb--;
  if (line.charAt(posb - 1) == ' ')   posb--;
  if (line.charAt(posa) == '<') {
    posa++;
    if (posb > posa && line.charAt(posb - 1) == '>')     posb--;
  }
  this.setObject(UnicodeEscape.unescapeString(line.substring(posa,posb)));
}

Fixed version (ground truth):
/** 
 * Read from a line, where each component is separated by space.
 * @param line
 */
public void read(String line) throws ParserException {
  int split, posa, posb;
  this.clear();
  posa=0;
  posb=split=line.indexOf(' ',posa);
  if (posb == -1)   return;
  if (line.charAt(posa) == '<')   posa++;
  if (line.charAt(posb - 1) == '>')   posb--;
  this.setSubject(line.substring(posa,posb));
  posa=split + 1;
  posb=split=line.indexOf(' ',posa);
  if (posb == -1)   return;
  if (line.charAt(posa) == '<')   posa++;
  if (posb > posa && line.charAt(posb - 1) == '>')   posb--;
  this.setPredicate(line.substring(posa,posb));
  posa=split + 1;
  posb=line.length();
  if (line.charAt(posb - 1) == '.')   posb--;
  if (line.charAt(posb - 1) == ' ')   posb--;
  if (line.charAt(posa) == '<') {
    posa++;
    if (posb > posa && line.charAt(posb - 1) == '>')     posb--;
  }
  this.setObject(UnicodeEscape.unescapeString(line.substring(posa,posb)));
}
Program: 22666
Project: 22666
Buggy source:
public void execute() throws ParserException, IOException {
  HDT hdt=HDTManager.loadIndexedHDT(hdtInput,this);
  BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
  TripleString cmd=new TripleString();
  while (true) {
    System.out.print("String_Node_Str");
    System.out.flush();
    String line=in.readLine();
    if (line == null || line.equals("String_Node_Str") || line.equals("String_Node_Str")) {
      break;
    }
    if (line.equals("String_Node_Str")) {
      System.out.println("String_Node_Str");
      System.out.println("String_Node_Str");
      System.out.println("String_Node_Str");
      System.out.println("String_Node_Str");
      continue;
    }
    cmd.read(line);
    System.out.println("String_Node_Str" + cmd.getSubject() + "String_Node_Str"+ cmd.getPredicate()+ "String_Node_Str"+ cmd.getObject()+ "String_Node_Str");
    iterate(hdt,cmd.getSubject(),cmd.getPredicate(),cmd.getObject());
  }
  in.close();
}

Fixed version (ground truth):
public void execute() throws IOException {
  HDT hdt=HDTManager.loadIndexedHDT(hdtInput,this);
  BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
  TripleString triplePattern=new TripleString();
  while (true) {
    System.out.print("String_Node_Str");
    System.out.flush();
    String line=in.readLine();
    if (line == null || line.equals("String_Node_Str") || line.equals("String_Node_Str")) {
      break;
    }
    if (line.equals("String_Node_Str")) {
      help();
      continue;
    }
    try {
      parseTriplePattern(triplePattern,line);
      System.out.println("String_Node_Str" + triplePattern.getSubject() + "String_Node_Str"+ triplePattern.getPredicate()+ "String_Node_Str"+ triplePattern.getObject()+ "String_Node_Str");
      iterate(hdt,triplePattern.getSubject(),triplePattern.getPredicate(),triplePattern.getObject());
    }
 catch (    ParserException e) {
      System.err.println("String_Node_Str" + e.getMessage());
      help();
    }
catch (    NotFoundException e) {
      System.err.println("String_Node_Str");
    }
  }
  in.close();
}
Program: 22667
Project: 22667
Buggy source:
protected static void iterate(HDT hdt,CharSequence subject,CharSequence predicate,CharSequence object){
  StopWatch iterateTime=new StopWatch();
  try {
    int count=0;
    subject=subject.length() == 1 && subject.charAt(0) == '?' ? "String_Node_Str" : subject;
    predicate=predicate.length() == 1 && predicate.charAt(0) == '?' ? "String_Node_Str" : predicate;
    object=object.length() == 1 && object.charAt(0) == '?' ? "String_Node_Str" : object;
    IteratorTripleString it=hdt.search(subject,predicate,object);
    count=0;
    while (it.hasNext()) {
      TripleString triple=it.next();
      System.out.println(triple);
      count++;
    }
    System.out.println("String_Node_Str" + count + "String_Node_Str"+ iterateTime.stopAndShow());
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
protected static void iterate(HDT hdt,CharSequence subject,CharSequence predicate,CharSequence object) throws NotFoundException {
  StopWatch iterateTime=new StopWatch();
  int count=0;
  subject=subject.length() == 1 && subject.charAt(0) == '?' ? "String_Node_Str" : subject;
  predicate=predicate.length() == 1 && predicate.charAt(0) == '?' ? "String_Node_Str" : predicate;
  object=object.length() == 1 && object.charAt(0) == '?' ? "String_Node_Str" : object;
  IteratorTripleString it=hdt.search(subject,predicate,object);
  count=0;
  while (it.hasNext()) {
    TripleString triple=it.next();
    System.out.println(triple);
    count++;
  }
  System.out.println("String_Node_Str" + count + "String_Node_Str"+ iterateTime.stopAndShow());
}
Program: 22668
Project: 22668
Buggy source:
@Override public void save(OutputStream output,ControlInfo ci,ProgressListener listener) throws IOException {
  ByteArrayOutputStream headerData=new ByteArrayOutputStream();
  IteratorTripleString iterator=this.search("String_Node_Str","String_Node_Str","String_Node_Str");
  while (iterator.hasNext()) {
    TripleString next=iterator.next();
    IOUtil.writeString(headerData,next.asNtriple().toString());
  }
  ci.clear();
  ci.setFormat(HDTVocabulary.HEADER_NTRIPLES);
  ci.setInt("String_Node_Str",headerData.size());
  ci.save(output);
  output.write(headerData.toByteArray());
}

Fixed version (ground truth):
@Override public void save(OutputStream output,ControlInfo ci,ProgressListener listener) throws IOException {
  ByteArrayOutputStream headerData=new ByteArrayOutputStream();
  IteratorTripleString iterator=this.search("String_Node_Str","String_Node_Str","String_Node_Str");
  while (iterator.hasNext()) {
    TripleString next=iterator.next();
    IOUtil.writeString(headerData,next.asNtriple().toString());
  }
  ci.clear();
  ci.setType(ControlInfo.Type.HEADER);
  ci.setFormat(HDTVocabulary.HEADER_NTRIPLES);
  ci.setInt("String_Node_Str",headerData.size());
  ci.save(output);
  output.write(headerData.toByteArray());
}
Program: 22669
Project: 22669
Buggy source:
@Override public boolean readAndCheck(InputStream in) throws IOException {
  short readCRC=IOUtil.readShort(in);
  return (readCRC == crc16);
}

Fixed version (ground truth):
@Override public boolean readAndCheck(InputStream in) throws IOException {
  int readCRC=IOUtil.readShort(in) & 0xFFFF;
  return (readCRC == crc16);
}
Program: 22670
Project: 22670
Buggy source:
@Override public void writeCRC(OutputStream out) throws IOException {
  IOUtil.writeShort(out,crc16);
}

Fixed version (ground truth):
@Override public void writeCRC(OutputStream out) throws IOException {
  IOUtil.writeShort(out,(short)crc16);
}
Program: 22671
Project: 22671
Buggy source:
@Override public void update(byte data){
  int tbl_idx=(crc16 ^ data) & 0xff;
  crc16=(short)((crc16_table[tbl_idx] ^ (crc16 >>> 8)) & 0xffff);
}

Fixed version (ground truth):
@Override public void update(byte data){
  int tbl_idx=(crc16 ^ data) & 0xff;
  crc16=(crc16_table[tbl_idx] ^ crc16 >>> 8) & 0xFFFF;
}
Program: 22672
Project: 22672
Buggy source:
@Override public void remove(){
  throw new NotImplementedException();
}

Fixed version (ground truth):
@Override public void remove(){
  iterator.remove();
}
Program: 22673
Project: 22673
Buggy source:
@Override public void goToStart(){
  prevY=-1;
  posY=adjY.findNextAppearance(0,patY);
  nextY=adjY.findNextAppearance(posY + 1,patY);
  posZ=prevZ=adjZ.find(posY);
  nextZ=adjZ.last(posY);
  x=(int)adjY.findListIndex(posY) + 1;
  y=(int)adjY.get(posY);
  z=(int)adjY.get(posZ);
}

Fixed version (ground truth):
@Override public void goToStart(){
  prevY=-1;
  posY=adjY.findNextAppearance(0,patY);
  nextY=adjY.findNextAppearance(posY + 1,patY);
  posZ=prevZ=adjZ.find(posY);
  nextZ=adjZ.last(posY);
  x=(int)adjY.findListIndex(posY) + 1;
  y=(int)adjY.get(posY);
  z=(int)adjZ.get(posZ);
}
Program: 22674
Project: 22674
Buggy source:
@Override public CharSequence subSequence(int start,int end){
  if (start < 0 || end >= (this.length())) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start + 1];
  System.arraycopy(buffer,start,newdata,0,end - start + 1);
  return new ReplazableString(newdata);
}

Fixed version (ground truth):
@Override public CharSequence subSequence(int start,int end){
  if (start < 0 || end > (this.length()) || (end - start) < 0) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start];
  System.arraycopy(buffer,start,newdata,0,end - start);
  return new ReplazableString(newdata);
}
Program: 22675
Project: 22675
Buggy source:
/** 
 * @param din
 * @param bytes
 * @param listener
 * @return
 */
public static final byte[] readBuffer(DataInputStream input,int length,ProgressListener listener) throws IOException {
  byte[] buffer=new byte[length];
  input.read(buffer,0,length);
  return buffer;
}

Fixed version (ground truth):
/** 
 * @param din
 * @param bytes
 * @param listener
 * @return
 */
public static final byte[] readBuffer(InputStream input,int length,ProgressListener listener) throws IOException {
  int nRead;
  int pos=0;
  byte[] data=new byte[length];
  while ((nRead=input.read(data,pos,length - pos)) > 0) {
    pos+=nRead;
  }
  if (pos != length) {
    throw new IOException("String_Node_Str");
  }
  return data;
}
Program: 22676
Project: 22676
Buggy source:
public static String readChars(DataInputStream in,int numChars) throws IOException {
  StringBuilder out=new StringBuilder();
  for (int i=0; i < numChars; i++) {
    char c=(char)in.readByte();
    out.append(c);
  }
  return out.toString();
}

Fixed version (ground truth):
public static String readChars(DataInput in,int numChars) throws IOException {
  StringBuilder out=new StringBuilder();
  for (int i=0; i < numChars; i++) {
    char c=(char)in.readByte();
    out.append(c);
  }
  return out.toString();
}