From b5991d2ee34ed19b413dfbf796a1f02a2b0d172e Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Sun, 28 Jun 2026 22:43:55 +0200 Subject: [PATCH] fix: uninitialized lateinit fixes ETCHDROID-F --- .../eu/depau/etchdroid/service/WorkerService.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/depau/etchdroid/service/WorkerService.kt b/app/src/main/java/eu/depau/etchdroid/service/WorkerService.kt index 0d45703..3b9f461 100644 --- a/app/src/main/java/eu/depau/etchdroid/service/WorkerService.kt +++ b/app/src/main/java/eu/depau/etchdroid/service/WorkerService.kt @@ -327,10 +327,16 @@ class WorkerService : LifecycleService() { startForegroundSpecialUse(mProgressNotificationId, basicForegroundNotification) } catch (exception: Exception) { Telemetry.captureException("Failed to start worker service", exception) - val downstreamException = exception as? EtchDroidException ?: UnknownException(exception) - getErrorIntent( - mSourceUri, mDestDevice, mJobId, 0, 0, exception = downstreamException - ).broadcastLocallySync(this@WorkerService) + // mDestDevice (and mSourceUri/mJobId) may be unset if we failed before parsing + // them; getErrorIntent needs a device, so only broadcast when we have one, + // otherwise reading the uninitialized lateinit would crash the service itself. + if (::mDestDevice.isInitialized) { + val downstreamException = + exception as? EtchDroidException ?: UnknownException(exception) + getErrorIntent( + mSourceUri, mDestDevice, mJobId, 0, 0, exception = downstreamException + ).broadcastLocallySync(this@WorkerService) + } stopSelf() return START_NOT_STICKY }