Program: 84960
Project: 84960
Buggy source:
private int sendFile(BluetoothOppSendFileInfo fileInfo){
  boolean error=false;
  int responseCode=-1;
  int status=BluetoothShare.STATUS_SUCCESS;
  Uri contentUri=Uri.parse(BluetoothShare.CONTENT_URI + "String_Node_Str" + mInfo.mId);
  ContentValues updateValues;
  HeaderSet request;
  request=new HeaderSet();
  request.setHeader(HeaderSet.NAME,fileInfo.mFileName);
  request.setHeader(HeaderSet.TYPE,fileInfo.mMimetype);
  Constants.updateShareStatus(mContext1,mInfo.mId,BluetoothShare.STATUS_RUNNING);
  request.setHeader(HeaderSet.LENGTH,fileInfo.mLength);
  ClientOperation putOperation=null;
  OutputStream outputStream=null;
  InputStream inputStream=null;
  try {
synchronized (this) {
      mWaitingForRemote=true;
    }
    try {
      if (Constants.LOGVV) {
        Log.v(TAG,"String_Node_Str" + fileInfo.mFileName);
      }
      putOperation=(ClientOperation)mCs.put(request);
    }
 catch (    IOException e) {
      status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
      Constants.updateShareStatus(mContext1,mInfo.mId,status);
      Log.e(TAG,"String_Node_Str");
      error=true;
    }
synchronized (this) {
      mWaitingForRemote=false;
    }
    if (!error) {
      try {
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mFileName);
        }
        outputStream=putOperation.openOutputStream();
        inputStream=putOperation.openInputStream();
      }
 catch (      IOException e) {
        status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
        Constants.updateShareStatus(mContext1,mInfo.mId,status);
        Log.e(TAG,"String_Node_Str");
        error=true;
      }
    }
    if (!error) {
      updateValues=new ContentValues();
      updateValues.put(BluetoothShare.CURRENT_BYTES,0);
      updateValues.put(BluetoothShare.STATUS,BluetoothShare.STATUS_RUNNING);
      mContext1.getContentResolver().update(contentUri,updateValues,null,null);
    }
    if (!error) {
      int position=0;
      int readLength=0;
      boolean okToProceed=false;
      long timestamp;
      int outputBufferSize=putOperation.getMaxPacketSize();
      byte[] buffer=new byte[outputBufferSize];
      BufferedInputStream a=new BufferedInputStream(fileInfo.mInputStream,0x4000);
      while (!mInterrupted && (position != fileInfo.mLength)) {
        if (Constants.LOGVV) {
          timestamp=System.currentTimeMillis();
        }
        readLength=a.read(buffer,0,outputBufferSize);
        if (!okToProceed) {
          mCallback.sendMessageDelayed(mCallback.obtainMessage(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT),BluetoothOppObexSession.SESSION_TIMEOUT);
        }
        outputStream.write(buffer,0,readLength);
        mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT);
        if (!okToProceed) {
          if (responseCode == -1 && position == fileInfo.mLength) {
            outputStream.close();
          }
          responseCode=putOperation.getResponseCode();
          if (responseCode == ResponseCodes.OBEX_HTTP_CONTINUE || responseCode == ResponseCodes.OBEX_HTTP_OK) {
            if (Constants.LOGVV) {
              Log.v(TAG,"String_Node_Str" + responseCode);
            }
            okToProceed=true;
          }
 else {
            Log.e(TAG,"String_Node_Str" + responseCode);
            break;
          }
        }
 else {
          responseCode=putOperation.getResponseCode();
          if (Constants.LOGVV) {
            Log.v(TAG,"String_Node_Str" + responseCode);
          }
          if (responseCode != ResponseCodes.OBEX_HTTP_CONTINUE && responseCode != ResponseCodes.OBEX_HTTP_OK) {
            break;
          }
        }
        position+=readLength;
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + position + "String_Node_Str"+ readLength+ "String_Node_Str"+ (System.currentTimeMillis() - timestamp)+ "String_Node_Str");
        }
        if (Constants.USE_EMULATOR_DEBUG) {
synchronized (this) {
            try {
              wait(300);
            }
 catch (            InterruptedException e) {
              error=true;
              status=BluetoothShare.STATUS_CANCELED;
              if (Constants.LOGVV) {
                Log.v(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ position+ "String_Node_Str"+ position);
              }
              Constants.updateShareStatus(mContext1,mInfo.mId,status);
            }
          }
        }
        updateValues=new ContentValues();
        updateValues.put(BluetoothShare.CURRENT_BYTES,position);
        mContext1.getContentResolver().update(contentUri,updateValues,null,null);
      }
      if (responseCode == ResponseCodes.OBEX_HTTP_FORBIDDEN) {
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ fileInfo.mLength);
        }
        status=BluetoothShare.STATUS_FORBIDDEN;
      }
 else       if (responseCode == ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE) {
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mMimetype);
        }
        status=BluetoothShare.STATUS_NOT_ACCEPTABLE;
      }
 else       if (!mInterrupted && position == fileInfo.mLength) {
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ fileInfo.mLength);
        }
        outputStream.close();
      }
 else {
        error=true;
        status=BluetoothShare.STATUS_CANCELED;
        putOperation.abort();
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ position+ "String_Node_Str"+ fileInfo.mLength);
        }
      }
    }
  }
 catch (  IOException e) {
    status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
    Log.e(TAG,"String_Node_Str");
    Constants.updateShareStatus(mContext1,mInfo.mId,status);
    mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT);
  }
 finally {
    try {
      fileInfo.mInputStream.close();
      if (!error) {
        responseCode=putOperation.getResponseCode();
        if (responseCode != -1) {
          Log.v(TAG,"String_Node_Str" + responseCode);
          if (responseCode == ResponseCodes.OBEX_HTTP_OK) {
            Log.v(TAG,"String_Node_Str");
          }
 else {
            Log.v(TAG,"String_Node_Str");
            status=BluetoothShare.STATUS_UNHANDLED_OBEX_CODE;
            if (responseCode == ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE) {
              status=BluetoothShare.STATUS_NOT_ACCEPTABLE;
            }
            if (responseCode == ResponseCodes.OBEX_HTTP_FORBIDDEN) {
              status=BluetoothShare.STATUS_FORBIDDEN;
            }
          }
        }
 else {
          status=BluetoothShare.STATUS_CONNECTION_ERROR;
        }
      }
      Constants.updateShareStatus(mContext1,mInfo.mId,status);
      if (inputStream != null) {
        inputStream.close();
      }
      if (putOperation != null) {
        putOperation.close();
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"String_Node_Str");
    }
  }
  return status;
}

Fixed version (ground truth):
private int sendFile(BluetoothOppSendFileInfo fileInfo){
  boolean error=false;
  int responseCode=-1;
  int status=BluetoothShare.STATUS_SUCCESS;
  Uri contentUri=Uri.parse(BluetoothShare.CONTENT_URI + "String_Node_Str" + mInfo.mId);
  ContentValues updateValues;
  HeaderSet request;
  request=new HeaderSet();
  request.setHeader(HeaderSet.NAME,fileInfo.mFileName);
  request.setHeader(HeaderSet.TYPE,fileInfo.mMimetype);
  Constants.updateShareStatus(mContext1,mInfo.mId,BluetoothShare.STATUS_RUNNING);
  request.setHeader(HeaderSet.LENGTH,fileInfo.mLength);
  ClientOperation putOperation=null;
  OutputStream outputStream=null;
  InputStream inputStream=null;
  try {
synchronized (this) {
      mWaitingForRemote=true;
    }
    try {
      if (Constants.LOGVV) {
        Log.v(TAG,"String_Node_Str" + fileInfo.mFileName);
      }
      putOperation=(ClientOperation)mCs.put(request);
    }
 catch (    IOException e) {
      status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
      Constants.updateShareStatus(mContext1,mInfo.mId,status);
      Log.e(TAG,"String_Node_Str");
      error=true;
    }
synchronized (this) {
      mWaitingForRemote=false;
    }
    if (!error) {
      try {
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + fileInfo.mFileName);
        }
        outputStream=putOperation.openOutputStream();
        inputStream=putOperation.openInputStream();
      }
 catch (      IOException e) {
        status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
        Constants.updateShareStatus(mContext1,mInfo.mId,status);
        Log.e(TAG,"String_Node_Str");
        error=true;
      }
    }
    if (!error) {
      updateValues=new ContentValues();
      updateValues.put(BluetoothShare.CURRENT_BYTES,0);
      updateValues.put(BluetoothShare.STATUS,BluetoothShare.STATUS_RUNNING);
      mContext1.getContentResolver().update(contentUri,updateValues,null,null);
    }
    if (!error) {
      int position=0;
      int readLength=0;
      boolean okToProceed=false;
      long timestamp=0;
      int outputBufferSize=putOperation.getMaxPacketSize();
      byte[] buffer=new byte[outputBufferSize];
      BufferedInputStream a=new BufferedInputStream(fileInfo.mInputStream,0x4000);
      while (!mInterrupted && (position != fileInfo.mLength)) {
        if (Constants.LOGVV) {
          timestamp=System.currentTimeMillis();
        }
        readLength=a.read(buffer,0,outputBufferSize);
        if (!okToProceed) {
          mCallback.sendMessageDelayed(mCallback.obtainMessage(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT),BluetoothOppObexSession.SESSION_TIMEOUT);
        }
        outputStream.write(buffer,0,readLength);
        mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT);
        position+=readLength;
        if (!okToProceed) {
          if (responseCode == -1 && position == fileInfo.mLength) {
            outputStream.close();
          }
          responseCode=putOperation.getResponseCode();
          if (responseCode == ResponseCodes.OBEX_HTTP_CONTINUE || responseCode == ResponseCodes.OBEX_HTTP_OK) {
            if (Constants.LOGVV) {
              Log.v(TAG,"String_Node_Str" + responseCode);
            }
            okToProceed=true;
          }
 else {
            Log.e(TAG,"String_Node_Str" + responseCode);
            break;
          }
        }
 else {
          responseCode=putOperation.getResponseCode();
          if (Constants.LOGVV) {
            Log.v(TAG,"String_Node_Str" + responseCode);
          }
          if (responseCode != ResponseCodes.OBEX_HTTP_CONTINUE && responseCode != ResponseCodes.OBEX_HTTP_OK) {
            break;
          }
        }
        if (Constants.LOGVV) {
          Log.v(TAG,"String_Node_Str" + position + "String_Node_Str"+ readLength+ "String_Node_Str"+ (System.currentTimeMillis() - timestamp)+ "String_Node_Str");
        }
        if (Constants.USE_EMULATOR_DEBUG) {
synchronized (this) {
            try {
              wait(300);
            }
 catch (            InterruptedException e) {
              error=true;
              status=BluetoothShare.STATUS_CANCELED;
              if (Constants.LOGVV) {
                Log.v(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ position+ "String_Node_Str"+ position);
              }
              Constants.updateShareStatus(mContext1,mInfo.mId,status);
            }
          }
        }
        updateValues=new ContentValues();
        updateValues.put(BluetoothShare.CURRENT_BYTES,position);
        mContext1.getContentResolver().update(contentUri,updateValues,null,null);
      }
      if (responseCode == ResponseCodes.OBEX_HTTP_FORBIDDEN) {
        Log.i(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ fileInfo.mLength);
        status=BluetoothShare.STATUS_FORBIDDEN;
      }
 else       if (responseCode == ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE) {
        Log.i(TAG,"String_Node_Str" + fileInfo.mMimetype);
        status=BluetoothShare.STATUS_NOT_ACCEPTABLE;
      }
 else       if (!mInterrupted && position == fileInfo.mLength) {
        Log.i(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ fileInfo.mLength);
        outputStream.close();
      }
 else {
        error=true;
        status=BluetoothShare.STATUS_CANCELED;
        putOperation.abort();
        Log.e(TAG,"String_Node_Str" + fileInfo.mFileName + "String_Node_Str"+ position+ "String_Node_Str"+ fileInfo.mLength);
      }
    }
  }
 catch (  IOException e) {
    status=BluetoothShare.STATUS_OBEX_DATA_ERROR;
    Log.e(TAG,"String_Node_Str");
    Constants.updateShareStatus(mContext1,mInfo.mId,status);
    mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT);
  }
 finally {
    try {
      fileInfo.mInputStream.close();
      if (!error) {
        responseCode=putOperation.getResponseCode();
        if (responseCode != -1) {
          if (Constants.LOGVV) {
            Log.v(TAG,"String_Node_Str" + responseCode);
          }
          if (responseCode != ResponseCodes.OBEX_HTTP_OK) {
            Log.i(TAG,"String_Node_Str" + responseCode);
            status=BluetoothShare.STATUS_UNHANDLED_OBEX_CODE;
            if (responseCode == ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE) {
              status=BluetoothShare.STATUS_NOT_ACCEPTABLE;
            }
            if (responseCode == ResponseCodes.OBEX_HTTP_FORBIDDEN) {
              status=BluetoothShare.STATUS_FORBIDDEN;
            }
          }
        }
 else {
          status=BluetoothShare.STATUS_CONNECTION_ERROR;
        }
      }
      Constants.updateShareStatus(mContext1,mInfo.mId,status);
      if (inputStream != null) {
        inputStream.close();
      }
      if (putOperation != null) {
        putOperation.close();
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"String_Node_Str");
    }
  }
  return status;
}