fix: improve null-safety handling in filter logic

to avoid NullPointerException: it.name must not be null at com.geeksville.mesh.repository.bluetooth.BluetoothRepository$createBondedDevicesFlow$2.invokeSuspend(BluetoothRepository.kt:96)
This commit is contained in:
andrekir
2023-04-13 17:11:40 -03:00
parent 5599a5d2a5
commit 28b905db23

View File

@@ -93,7 +93,7 @@ class BluetoothRepository @Inject constructor(
return flow<List<BluetoothDevice>> {
val devices = adapter.bondedDevices ?: emptySet()
while (true) {
emit(devices.filter { it.name != null && it.name.matches(Regex(BLE_NAME_PATTERN)) })
emit(devices.filter { it.name?.matches(Regex(BLE_NAME_PATTERN)) == true })
delay(REFRESH_DELAY_MS)
}
}.flowOn(dispatchers.default).distinctUntilChanged()