Program: 29693
Project: 29693
Buggy source:
public void addData(byte[] datachunk){
  for (int i=0; i < datachunk.length; i++) {
    if (bresponse.toByteArray().length < 4) {
      bresponse.write(datachunk[i]);
      if (response.length() == 0 && bresponse.toByteArray().length == 4) {
        response=new String(bresponse.toByteArray());
      }
    }
 else {
      if (response.equals("String_Node_Str") || response.equals("String_Node_Str")) {
        bdata.write(datachunk[i]);
      }
 else       if (response.equals("String_Node_Str")) {
        if (blength.toByteArray().length < 8) {
          blength.write(datachunk[i]);
          if (length == -1 && blength.toByteArray().length == 8) {
            length=BytesUtil.getInt(blength.toByteArray());
          }
        }
 else {
          if (((char)datachunk[i] == 'O' || (char)datachunk[i] == 'F') && tmpdata.toByteArray().length == 0) {
            tmpdata.write(datachunk[i]);
          }
 else           if (((char)datachunk[i] == 'K' || (char)datachunk[i] == 'A') && tmpdata.toByteArray().length == 1) {
            tmpdata.write(datachunk[i]);
          }
 else           if (((char)datachunk[i] == 'A' || (char)datachunk[i] == 'I') && tmpdata.toByteArray().length == 2) {
            tmpdata.write(datachunk[i]);
          }
 else           if (((char)datachunk[i] == 'Y' || (char)datachunk[i] == 'L') && tmpdata.toByteArray().length == 3) {
            tmpdata.write(datachunk[i]);
            response=new String(tmpdata.toByteArray());
          }
 else {
            if (tmpdata.toByteArray().length > 0) {
              byte[] result=BytesUtil.concatAll(bdata.toByteArray(),tmpdata.toByteArray());
              tmpdata=new ByteArrayOutputStream();
              bdata=new ByteArrayOutputStream();
              try {
                bdata.write(result);
              }
 catch (              IOException ioe) {
              }
            }
            bdata.write(datachunk[i]);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
public void addData(byte[] datachunk){
  for (int i=0; i < datachunk.length; i++) {
    if (bresponse.toByteArray().length < 4) {
      bresponse.write(datachunk[i]);
      if (response.length() == 0 && bresponse.toByteArray().length == 4) {
        response=new String(bresponse.toByteArray());
      }
    }
 else {
      if (response.equals("String_Node_Str") || response.equals("String_Node_Str")) {
        bdata.write(datachunk[i]);
      }
 else       if (response.equals("String_Node_Str")) {
        if (blength.toByteArray().length < 8) {
          blength.write(datachunk[i]);
          if (length == -1 && blength.toByteArray().length == 8) {
            length=BytesUtil.getInt(blength.toByteArray());
          }
        }
 else {
          tmpdata.write(datachunk[i]);
          try {
            if (new String(tmpdata.toByteArray()).endsWith("String_Node_Str")) {
              response="String_Node_Str";
              bdata.write(Arrays.copyOf(tmpdata.toByteArray(),tmpdata.toByteArray().length - 4));
            }
            if (new String(tmpdata.toByteArray()).endsWith("String_Node_Str")) {
              response="String_Node_Str";
              bdata.write(Arrays.copyOf(tmpdata.toByteArray(),tmpdata.toByteArray().length - 4));
            }
          }
 catch (          Exception e) {
          }
        }
      }
    }
  }
}