diff --git a/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java b/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java index 3addf9c4ac..89cce42c44 100644 --- a/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java +++ b/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java @@ -94,7 +94,7 @@ public class AttachmentUploadJob extends BaseJob { DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId); if (databaseAttachment == null) { - throw new IllegalStateException("Cannot find the specified attachment."); + throw new InvalidAttachmentException("Cannot find the specified attachment."); } MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints(); @@ -132,7 +132,9 @@ public class AttachmentUploadJob extends BaseJob { * The {@link PartProgressEvent} of this task will fit in the remaining * 1 - progressStartPoint. */ - private SignalServiceAttachment getAttachmentFor(Attachment attachment, @Nullable NotificationController notification, double progressStartPoint) { + private @NonNull SignalServiceAttachment getAttachmentFor(Attachment attachment, @Nullable NotificationController notification, double progressStartPoint) + throws InvalidAttachmentException + { try { if (attachment.getDataUri() == null || attachment.getSize() == 0) throw new IOException("Assertion failed, outgoing attachment has no data!"); InputStream is = PartAuthority.getAttachmentStream(context, attachment.getDataUri()); @@ -154,9 +156,8 @@ public class AttachmentUploadJob extends BaseJob { }) .build(); } catch (IOException ioe) { - Log.w(TAG, "Couldn't open attachment", ioe); + throw new InvalidAttachmentException(ioe); } - return null; } private Attachment scaleAndStripExif(@NonNull AttachmentDatabase attachmentDatabase, @@ -178,6 +179,16 @@ public class AttachmentUploadJob extends BaseJob { progressListener); } + private class InvalidAttachmentException extends Exception { + InvalidAttachmentException(String message) { + super(message); + } + + InvalidAttachmentException(Exception e) { + super(e); + } + } + public static final class Factory implements Job.Factory { @Override public @NonNull AttachmentUploadJob create(@NonNull Parameters parameters, @NonNull org.thoughtcrime.securesms.jobmanager.Data data) { diff --git a/src/org/thoughtcrime/securesms/jobs/TypingSendJob.java b/src/org/thoughtcrime/securesms/jobs/TypingSendJob.java index 0d0a1d06e2..8106dbdd9e 100644 --- a/src/org/thoughtcrime/securesms/jobs/TypingSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/TypingSendJob.java @@ -77,7 +77,8 @@ public class TypingSendJob extends BaseJob { Recipient recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId); if (recipient == null) { - throw new IllegalStateException("Tried to send a typing indicator to a non-existent thread."); + Log.w(TAG, "Tried to send a typing indicator to a non-existent thread."); + return; } List recipients = Collections.singletonList(recipient);