From b12286c892674cff1df71bd549e0c93823ae3587 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Fri, 6 Apr 2018 23:41:22 +0200 Subject: [PATCH] Handle possible null return Fixes #1052 --- .../freeyourgadget/gadgetbridge/util/DeviceHelper.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java index 01030d5e5..516e2ee09 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java @@ -20,6 +20,7 @@ package nodomain.freeyourgadget.gadgetbridge.util; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; +import android.support.annotation.NonNull; import android.widget.Toast; import org.slf4j.Logger; @@ -248,11 +249,18 @@ public class DeviceHelper { return gbDevice; } - private List getBondedDevices(BluetoothAdapter btAdapter) { + private @NonNull List getBondedDevices(@NonNull BluetoothAdapter btAdapter) { Set pairedDevices = btAdapter.getBondedDevices(); + if (pairedDevices == null) { + return Collections.emptyList(); + } + List result = new ArrayList<>(pairedDevices.size()); DeviceHelper deviceHelper = DeviceHelper.getInstance(); for (BluetoothDevice pairedDevice : pairedDevices) { + if (pairedDevice == null) { + continue; // just to be safe, see https://github.com/Freeyourgadget/Gadgetbridge/pull/1052 + } if (pairedDevice.getName() != null && (pairedDevice.getName().startsWith("Pebble-LE ") || pairedDevice.getName().startsWith("Pebble Time LE "))) { continue; // ignore LE Pebble (this is part of the main device now (volatileAddress) }