Check for nulls when opening ContentResolver streams

This commit is contained in:
Alexander Bakker 2022-11-03 22:41:30 +01:00
parent 1f69bf558e
commit bee490d091
5 changed files with 16 additions and 0 deletions

View file

@ -27,6 +27,9 @@ public class ExportTask extends ProgressDialogTask<ExportTask.Params, Exception>
ExportTask.Params params = args[0];
try (InputStream inStream = new FileInputStream(params.getFile());
OutputStream outStream = getDialog().getContext().getContentResolver().openOutputStream(params.getDestUri(), "w")) {
if (outStream == null) {
throw new IOException("openOutputStream returned null");
}
IOUtils.copy(inStream, outStream);
return null;
} catch (IOException e) {

View file

@ -29,6 +29,10 @@ public class ImportFileTask extends ProgressDialogTask<ImportFileTask.Params, Im
Params p = params[0];
try (InputStream inStream = context.getContentResolver().openInputStream(p.getUri())) {
if (inStream == null) {
throw new IOException("openInputStream returned null");
}
String prefix = p.getNamePrefix() != null ? p.getNamePrefix() + "-" : "";
String suffix = p.getNameSuffix() != null ? "-" + p.getNameSuffix() : "";

View file

@ -32,6 +32,9 @@ public class ImportIconPackTask extends ProgressDialogTask<ImportIconPackTask.Pa
tempFile = File.createTempFile("icon-pack-", "", context.getCacheDir());
try (InputStream inStream = context.getContentResolver().openInputStream(param.getUri());
FileOutputStream outStream = new FileOutputStream(tempFile)) {
if (inStream == null) {
throw new IOException("openInputStream returned null");
}
IOUtils.copy(inStream, outStream);
}

View file

@ -33,6 +33,9 @@ public class QrDecodeTask extends ProgressDialogTask<List<Uri>, List<QrDecodeTas
}
try (InputStream inStream = context.getContentResolver().openInputStream(uri)) {
if (inStream == null) {
throw new IOException("openInputStream returned null");
}
com.google.zxing.Result result = QrCodeHelper.decodeFromStream(inStream);
res.add(new Result(uri, fileName, result, null));
} catch (QrCodeHelper.DecodeError | IOException e) {

View file

@ -85,6 +85,9 @@ public class VaultBackupManager {
try (FileInputStream inStream = new FileInputStream(tempFile);
OutputStream outStream = _context.getContentResolver().openOutputStream(file.getUri())) {
if (outStream == null) {
throw new IOException("openOutputStream returned null");
}
IOUtils.copy(inStream, outStream);
} catch (IOException e) {
throw new VaultRepositoryException(e);