From 0f06e34011a981de1a317910a918b6afa2140fdd Mon Sep 17 00:00:00 2001 From: Armin Date: Thu, 26 Sep 2024 09:50:12 +0200 Subject: [PATCH] [RFR-1170] Fix NPE during upload attempt --- .../main/kotlin/de/cyface/synchronization/SyncAdapter.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/synchronization/src/main/kotlin/de/cyface/synchronization/SyncAdapter.kt b/synchronization/src/main/kotlin/de/cyface/synchronization/SyncAdapter.kt index 15e5bbdf..57c30669 100644 --- a/synchronization/src/main/kotlin/de/cyface/synchronization/SyncAdapter.kt +++ b/synchronization/src/main/kotlin/de/cyface/synchronization/SyncAdapter.kt @@ -615,8 +615,7 @@ class SyncAdapter private constructor( tracks.isEmpty() || (tracks[0].geoLocations.size > 0 && tracks[tracks.size - 1].geoLocations.size > 0) ) - val lastTrack: List? = - if (tracks.isNotEmpty()) tracks[tracks.size - 1].geoLocations else null + val lastTrack = if (tracks.isNotEmpty()) tracks[tracks.size - 1].geoLocations else null var startLocation: GeoLocation? = null if (tracks.isNotEmpty()) { val l = tracks[0].geoLocations[0]!! @@ -641,7 +640,9 @@ class SyncAdapter private constructor( } val filesSize = if (allAttachments > 0) { // TODO: support multiple attachments by zipping them - val attachment = persistence.attachmentDao!!.loadOneByMeasurementIdAndType(measurement.id, FileType.JSON) + // (!) we load the CSV file here as the location_metrics.csv should always exist + // if not, the upload crashes with an NPE. + val attachment = persistence.attachmentDao!!.loadOneByMeasurementIdAndType(measurement.id, FileType.CSV) val folderPath = File(attachment!!.path.parent.toUri()) getFolderSize(folderPath) } else 0