Program: 43185
Project: 43185
Buggy source:
/** 
 * Creates new ServerOperation
 * @param p the parent that created this object
 * @param in the input stream to read from
 * @param out the output stream to write to
 * @param request the initial request that was received from the client
 * @param maxSize the max packet size that the client will accept
 * @param listen the listener that is responding to the request
 * @throws IOException if an IO error occurs
 */
public ServerOperation(ServerSession p,InputStream in,int request,int maxSize,ServerRequestHandler listen) throws IOException {
  isAborted=false;
  mParent=p;
  mInput=in;
  mMaxPacketLength=maxSize;
  mClosed=false;
  requestHeader=new HeaderSet();
  replyHeader=new HeaderSet();
  mPrivateInput=new PrivateInputStream(this);
  mResponseSize=3;
  mListener=listen;
  mRequestFinished=false;
  mPrivateOutputOpen=false;
  mHasBody=false;
  int bytesReceived;
  if ((request == 0x02) || (request == 0x82)) {
    mGetOperation=false;
  }
 else {
    mGetOperation=true;
  }
  if ((request & 0x80) == 0) {
    finalBitSet=false;
  }
 else {
    finalBitSet=true;
    mRequestFinished=true;
  }
  int length=in.read();
  length=(length << 8) + in.read();
  if (length > ObexHelper.MAX_PACKET_SIZE_INT) {
    mParent.sendResponse(ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE,null);
    throw new IOException("String_Node_Str");
  }
  if (length > 3) {
    byte[] data=new byte[length - 3];
    bytesReceived=in.read(data);
    while (bytesReceived != data.length) {
      bytesReceived+=in.read(data,bytesReceived,data.length - bytesReceived);
    }
    byte[] body=ObexHelper.updateHeaderSet(requestHeader,data);
    if (body != null) {
      mHasBody=true;
    }
    if (requestHeader.mConnectionID != null) {
      mListener.setConnectionId(ObexHelper.convertToLong(requestHeader.mConnectionID));
    }
 else {
      mListener.setConnectionId(0);
    }
    if (requestHeader.mAuthResp != null) {
      if (!mParent.handleAuthResp(requestHeader.mAuthResp)) {
        mExceptionString="String_Node_Str";
        mParent.sendResponse(ResponseCodes.OBEX_HTTP_UNAUTHORIZED,null);
        mClosed=true;
        requestHeader.mAuthResp=null;
        return;
      }
    }
    if (requestHeader.mAuthChall != null) {
      mParent.handleAuthChall(requestHeader);
      replyHeader.mAuthResp=new byte[requestHeader.mAuthResp.length];
      System.arraycopy(requestHeader.mAuthResp,0,replyHeader.mAuthResp,0,replyHeader.mAuthResp.length);
      requestHeader.mAuthResp=null;
      requestHeader.mAuthChall=null;
    }
    if (body != null) {
      mPrivateInput.writeBytes(body,1);
    }
 else {
      while ((!mGetOperation) && (!finalBitSet)) {
        sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
        if (mPrivateInput.available() > 0) {
          break;
        }
      }
    }
  }
  while ((!mGetOperation) && (!finalBitSet) && (mPrivateInput.available() == 0)) {
    sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
    if (mPrivateInput.available() > 0) {
      break;
    }
  }
  while (mGetOperation && !finalBitSet) {
    sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
  }
  if (finalBitSet && mGetOperation) {
    mRequestFinished=true;
  }
}

Fixed version (ground truth):
/** 
 * Creates new ServerOperation
 * @param p the parent that created this object
 * @param in the input stream to read from
 * @param out the output stream to write to
 * @param request the initial request that was received from the client
 * @param maxSize the max packet size that the client will accept
 * @param listen the listener that is responding to the request
 * @throws IOException if an IO error occurs
 */
public ServerOperation(ServerSession p,InputStream in,int request,int maxSize,ServerRequestHandler listen) throws IOException {
  isAborted=false;
  mParent=p;
  mInput=in;
  mMaxPacketLength=maxSize;
  mClosed=false;
  requestHeader=new HeaderSet();
  replyHeader=new HeaderSet();
  mPrivateInput=new PrivateInputStream(this);
  mResponseSize=3;
  mListener=listen;
  mRequestFinished=false;
  mPrivateOutputOpen=false;
  mHasBody=false;
  int bytesReceived;
  if ((request == 0x02) || (request == 0x82)) {
    mGetOperation=false;
  }
 else {
    mGetOperation=true;
  }
  if ((request & 0x80) == 0) {
    finalBitSet=false;
  }
 else {
    finalBitSet=true;
    mRequestFinished=true;
  }
  int length=in.read();
  length=(length << 8) + in.read();
  if (length > ObexHelper.MAX_PACKET_SIZE_INT) {
    mParent.sendResponse(ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE,null);
    throw new IOException("String_Node_Str");
  }
  if (length > 3) {
    byte[] data=new byte[length - 3];
    bytesReceived=in.read(data);
    while (bytesReceived != data.length) {
      bytesReceived+=in.read(data,bytesReceived,data.length - bytesReceived);
    }
    byte[] body=ObexHelper.updateHeaderSet(requestHeader,data);
    if (body != null) {
      mHasBody=true;
    }
    if (mListener.getConnectionId() != -1 && requestHeader.mConnectionID != null) {
      mListener.setConnectionId(ObexHelper.convertToLong(requestHeader.mConnectionID));
    }
 else {
      mListener.setConnectionId(1);
    }
    if (requestHeader.mAuthResp != null) {
      if (!mParent.handleAuthResp(requestHeader.mAuthResp)) {
        mExceptionString="String_Node_Str";
        mParent.sendResponse(ResponseCodes.OBEX_HTTP_UNAUTHORIZED,null);
        mClosed=true;
        requestHeader.mAuthResp=null;
        return;
      }
    }
    if (requestHeader.mAuthChall != null) {
      mParent.handleAuthChall(requestHeader);
      replyHeader.mAuthResp=new byte[requestHeader.mAuthResp.length];
      System.arraycopy(requestHeader.mAuthResp,0,replyHeader.mAuthResp,0,replyHeader.mAuthResp.length);
      requestHeader.mAuthResp=null;
      requestHeader.mAuthChall=null;
    }
    if (body != null) {
      mPrivateInput.writeBytes(body,1);
    }
 else {
      while ((!mGetOperation) && (!finalBitSet)) {
        sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
        if (mPrivateInput.available() > 0) {
          break;
        }
      }
    }
  }
  while ((!mGetOperation) && (!finalBitSet) && (mPrivateInput.available() == 0)) {
    sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
    if (mPrivateInput.available() > 0) {
      break;
    }
  }
  while (mGetOperation && !finalBitSet) {
    sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
  }
  if (finalBitSet && mGetOperation) {
    mRequestFinished=true;
  }
}