Program: 162442
Project: 162442
Buggy source:
@Override public <E>E doInBackground(){
  for (  Uri uri : uris) {
    BufferedInputStream bufferedInputStream=null;
    try {
      bufferedInputStream=new BufferedInputStream(contentResolver.openInputStream(uri));
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
    BufferedOutputStream bufferedOutputStream=null;
    try {
      DocumentFile documentFile=DocumentFile.fromSingleUri(mainActivity,uri);
      String finalFilePath=currentPath + "String_Node_Str" + documentFile.getName();
      DataUtils dataUtils=DataUtils.getInstance();
      HybridFile hFile=new HybridFile(OpenMode.UNKNOWN,currentPath);
      hFile.generateMode(mainActivity);
switch (hFile.getMode()) {
case FILE:
case ROOT:
        if (!FileUtil.isWritable(new File(finalFilePath))) {
          AppConfig.toast(mainActivity,mainActivity.getResources().getString(R.string.not_allowed));
          return null;
        }
      bufferedOutputStream=new BufferedOutputStream(new FileOutputStream(finalFilePath));
    break;
case SMB:
  OutputStream outputStream=new SmbFile(finalFilePath).getOutputStream();
bufferedOutputStream=new BufferedOutputStream(outputStream);
break;
case DROPBOX:
CloudStorage cloudStorageDropbox=dataUtils.getAccount(OpenMode.DROPBOX);
cloudStorageDropbox.upload(CloudUtil.stripPath(OpenMode.DROPBOX,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case BOX:
CloudStorage cloudStorageBox=dataUtils.getAccount(OpenMode.BOX);
cloudStorageBox.upload(CloudUtil.stripPath(OpenMode.BOX,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case ONEDRIVE:
CloudStorage cloudStorageOneDrive=dataUtils.getAccount(OpenMode.ONEDRIVE);
cloudStorageOneDrive.upload(CloudUtil.stripPath(OpenMode.ONEDRIVE,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case GDRIVE:
CloudStorage cloudStorageGDrive=dataUtils.getAccount(OpenMode.GDRIVE);
cloudStorageGDrive.upload(CloudUtil.stripPath(OpenMode.GDRIVE,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case OTG:
DocumentFile documentTargetFile=OTGUtil.getDocumentFile(finalFilePath,mainActivity,true);
bufferedOutputStream=new BufferedOutputStream(contentResolver.openOutputStream(documentTargetFile.getUri()),GenericCopyUtil.DEFAULT_BUFFER_SIZE);
break;
default :
return null;
}
int count=0;
byte[] buffer=new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
while (count != -1) {
count=bufferedInputStream.read(buffer);
if (count != -1) {
bufferedOutputStream.write(buffer,0,count);
}
}
bufferedOutputStream.flush();
}
 catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
 finally {
try {
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
if (bufferedOutputStream != null) {
bufferedOutputStream.close();
}
}
 catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}

Fixed version (ground truth):
@Override public <E>E doInBackground(){
  for (  Uri uri : uris) {
    BufferedInputStream bufferedInputStream=null;
    try {
      bufferedInputStream=new BufferedInputStream(contentResolver.openInputStream(uri));
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
    BufferedOutputStream bufferedOutputStream=null;
    try {
      DocumentFile documentFile=DocumentFile.fromSingleUri(mainActivity,uri);
      String finalFilePath=currentPath + "String_Node_Str" + documentFile.getName();
      DataUtils dataUtils=DataUtils.getInstance();
      HybridFile hFile=new HybridFile(OpenMode.UNKNOWN,currentPath);
      hFile.generateMode(mainActivity);
switch (hFile.getMode()) {
case FILE:
case ROOT:
        File targetFile=new File(finalFilePath);
      if (!FileUtil.isWritable(targetFile)) {
        AppConfig.toast(mainActivity,mainActivity.getString(R.string.not_allowed));
        return null;
      }
    if (DocumentFile.fromFile(targetFile).exists()) {
      AppConfig.toast(mainActivity,mainActivity.getString(R.string.cannot_overwrite));
      return null;
    }
  bufferedOutputStream=new BufferedOutputStream(new FileOutputStream(targetFile));
break;
case SMB:
SmbFile targetSmbFile=new SmbFile(finalFilePath);
if (targetSmbFile.exists()) {
AppConfig.toast(mainActivity,mainActivity.getString(R.string.cannot_overwrite));
return null;
}
 else {
OutputStream outputStream=targetSmbFile.getOutputStream();
bufferedOutputStream=new BufferedOutputStream(outputStream);
}
break;
case SFTP:
AppConfig.toast(mainActivity,mainActivity.getString(R.string.not_allowed));
return null;
case DROPBOX:
CloudStorage cloudStorageDropbox=dataUtils.getAccount(OpenMode.DROPBOX);
cloudStorageDropbox.upload(CloudUtil.stripPath(OpenMode.DROPBOX,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case BOX:
CloudStorage cloudStorageBox=dataUtils.getAccount(OpenMode.BOX);
cloudStorageBox.upload(CloudUtil.stripPath(OpenMode.BOX,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case ONEDRIVE:
CloudStorage cloudStorageOneDrive=dataUtils.getAccount(OpenMode.ONEDRIVE);
cloudStorageOneDrive.upload(CloudUtil.stripPath(OpenMode.ONEDRIVE,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case GDRIVE:
CloudStorage cloudStorageGDrive=dataUtils.getAccount(OpenMode.GDRIVE);
cloudStorageGDrive.upload(CloudUtil.stripPath(OpenMode.GDRIVE,finalFilePath),bufferedInputStream,documentFile.length(),true);
break;
case OTG:
DocumentFile documentTargetFile=OTGUtil.getDocumentFile(finalFilePath,mainActivity,true);
if (documentTargetFile.exists()) {
AppConfig.toast(mainActivity,mainActivity.getString(R.string.cannot_overwrite));
return null;
}
bufferedOutputStream=new BufferedOutputStream(contentResolver.openOutputStream(documentTargetFile.getUri()),GenericCopyUtil.DEFAULT_BUFFER_SIZE);
break;
default :
return null;
}
int count=0;
byte[] buffer=new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
while (count != -1) {
count=bufferedInputStream.read(buffer);
if (count != -1) {
bufferedOutputStream.write(buffer,0,count);
}
}
bufferedOutputStream.flush();
}
 catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
 finally {
try {
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
if (bufferedOutputStream != null) {
bufferedOutputStream.close();
}
}
 catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}