Skip to content

[bluetooth.bluez] NullPointerException in getDBusBlueZCharacteristicByUUID #18180

@jlaur

Description

@jlaur

During my work on #16116 I noticed this morning that I stopped receiving data around 7:46, which I noticed around 8:31 and restarted the Thing:

Persisted states

2025-01-24 07:45:42.946, 6.72412109375
2025-01-24 07:46:12.973, 6.7528076171875
2025-01-24 07:46:42.977, 6.6954345703125
2025-01-24 08:31:42.122, 7.584716796875

When inspecting logs, I found this exception:

2025-01-24 07:47:12.833 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NullPointerException: Cannot invoke "com.github.hypfvieh.bluetooth.wrapper.BluetoothGattCharacteristic.getUuid()" because "c" is null
        at org.openhab.binding.bluetooth.bluez.internal.BlueZBluetoothDevice.getDBusBlueZCharacteristicByUUID(BlueZBluetoothDevice.java:223) ~[?:?]
        at org.openhab.binding.bluetooth.bluez.internal.BlueZBluetoothDevice.writeCharacteristic(BlueZBluetoothDevice.java:309) ~[?:?]
        at org.openhab.binding.bluetooth.grundfosalpha.internal.handler.GrundfosAlpha3Handler.refreshChannels(GrundfosAlpha3Handler.java:202) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:840) [?:?]
2025-01-24 07:47:12.835 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NullPointerException: Cannot invoke "com.github.hypfvieh.bluetooth.wrapper.BluetoothGattCharacteristic.getUuid()" because "c" is null
        at org.openhab.binding.bluetooth.bluez.internal.BlueZBluetoothDevice.getDBusBlueZCharacteristicByUUID(BlueZBluetoothDevice.java:223) ~[?:?]
        at org.openhab.binding.bluetooth.bluez.internal.BlueZBluetoothDevice.writeCharacteristic(BlueZBluetoothDevice.java:309) ~[?:?]
        at org.openhab.binding.bluetooth.grundfosalpha.internal.handler.GrundfosAlpha3Handler.refreshChannels(GrundfosAlpha3Handler.java:202) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:840) [?:?]

Expected Behavior

The BlueZ Bridge should not throw runtime exceptions.

Current Behavior

Under unknown circumstances, a NullPointerException is thrown.

Possible Solution

Line 223 here (as shown in the stack trace):

for (BluetoothGattCharacteristic c : service.getGattCharacteristics()) {
if (c.getUuid().equalsIgnoreCase(uuid)) {

could be changed to:

if (uuid.equalsIgnoreCase(c.getUuid())) { 

It seems like it's possible that this method:

https://github.com/jlaur/bluez-dbus/blob/567468884585b5a34bdc42b8577d9acbbc031659/bluez-dbus/src/main/java/com/github/hypfvieh/bluetooth/wrapper/BluetoothGattService.java#L54-L63

returns a List with a null object, and therefore I would also suspect a bug in this library, which should be checked. I did not yet check if anything related was changed in the recent 0.1.4 to 0.3.1 upgrade: #18124, #18146.

Steps to Reproduce

Not yet known.

Context

Your Environment

  • Version used: 4.3.2
  • Operating System and version: Linux openhabian 6.6.28+rpt-rpi-2712 Fixed URL for "how to contribute" #1 SMP PREEMPT Debian 1:6.6.28-1+rpt1 (2024-04-22) aarch64 GNU/Linux

Metadata

Metadata

Assignees

Labels

bugAn unexpected problem or unintended behavior of an add-on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions