Return safely if destroy() is called before start().

This commit is contained in:
akwizgran
2022-06-20 12:20:15 +01:00
parent 0aff23a067
commit aeb2a370e1
2 changed files with 2 additions and 2 deletions

View File

@@ -90,7 +90,7 @@ class ContactMailboxDownloadWorker implements MailboxWorker,
LOG.info("Started");
synchronized (lock) {
// Don't allow the worker to be reused
if (state != State.CREATED) throw new IllegalStateException();
if (state != State.CREATED) return;
state = State.CONNECTIVITY_CHECK;
}
// Avoid leaking observer in case destroy() is called concurrently

View File

@@ -147,7 +147,7 @@ class MailboxUploadWorker implements MailboxWorker, ConnectivityObserver,
LOG.info("Started");
synchronized (lock) {
// Don't allow the worker to be reused
if (state != State.CREATED) throw new IllegalStateException();
if (state != State.CREATED) return;
state = State.CHECKING_FOR_DATA;
}
ioExecutor.execute(this::checkForDataToSend);