Fixes for NullPointerException spotted on Play Store

These are probably edge cases but they do appear to happen occasionally

Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int android.bluetooth.BluetoothClass.getDeviceClass()' on a null object reference
  at nodomain.freeyourgadget.gadgetbridge.devices.generic_headphones.GenericHeadphonesCoordinator.supports (GenericHeadphonesCoordinator.java:45)
  at nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper.resolveDeviceType (DeviceHelper.java:140)
  at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processCandidate (GBScanEventProcessor.java:175)
  at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processAllScanEvents (GBScanEventProcessor.java:237)
  at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.run (GBScanEventProcessor.java:81)
  at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor$1.run (GBScanEventProcessor.java:103)

Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference
  at android.bluetooth.BluetoothSocket.read (BluetoothSocket.java:692)
  at android.bluetooth.BluetoothInputStream.read (BluetoothInputStream.java:88)
  at java.io.InputStream.read (InputStream.java:218)
  at nodomain.freeyourgadget.gadgetbridge.service.btbr.BtBRQueue$1.run (BtBRQueue.java:73)
This commit is contained in:
Gordon Williams
2025-06-20 10:48:34 +01:00
parent 52d3b20430
commit 849997b145
2 changed files with 5 additions and 1 deletions
@@ -42,6 +42,7 @@ public class GenericHeadphonesCoordinator extends AbstractDeviceCoordinator {
try {
final BluetoothDevice device = candidate.getDevice();
final BluetoothClass deviceClass = device.getBluetoothClass();
if (deviceClass == null) return false;
int deviceType = deviceClass.getDeviceClass();
return deviceType == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET ||
deviceType == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES ||
@@ -64,12 +64,15 @@ public final class BtBRQueue {
@Override
public void run() {
final byte[] buffer = new byte[mBufferSize];
int nRead;
int nRead = 0;
LOG.debug("Read thread started, entering loop");
while (!mDisposed) {
try {
if (mBtSocket == null)
throw new IOException("mBtSocket was null");
nRead = mBtSocket.getInputStream().read(buffer);
// safety measure