zsmartsystems / com.zsmartsystems.zigbee

ZigBee Cluster Library Java framework supporting multiple dongles
Eclipse Public License 1.0
142 stars 88 forks source link

NullPointerException in ZclCluster.readAttributeValue #1288

Closed TomTravaglino closed 2 years ago

TomTravaglino commented 2 years ago

Sometimes this Exception is thrown:

java.lang.NullPointerException: null
at com.zsmartsystems.zigbee.zcl.ZclCluster.readAttributeValue(readAttributeValue:480)
at com.zsmartsystems.zigbee.zcl.ZclAttribute.readValue(readValue:193)
at com.zsmartsystems.zigbee.app.iasclient.ZclIasZoneClient.initialise(initialise:220)
at com.zsmartsystems.zigbee.app.iasclient.ZclIasZoneClient.appStartup(appStartup:192)
at com.zsmartsystems.zigbee.ZigBeeEndpoint.addApplication(addApplication:413)
at com.zsmartsystems.zigbee.app.iasclient.ZigBeeIasCieExtension.nodeAdded(nodeAdded:55)
at com.zsmartsystems.zigbee.ZigBeeNetworkManager$7.run(run:1380)
at java.util.concurrent.ThreadPoolExecutor.runWorker(runWorker:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(run:624)
at java.lang.Thread.run(run:748)

The Exception is thrown by this statement: result = readAttribute(attributeId).get(); readAttribute returns a Future and apparently it is null in that case. Starting from readAttribute I followed the invocations and in ZigBeeTransactionManager.queueTransaction(...) I saw this statement

if (isShutdown) {
    logger.debug("Transaction Manager is shutdown. Transaction not sent: {}", transaction);
    return null;
}

Since returning a null value is intended, I suggest to null-check the Future in ZclCluster.readAttributeValue. I will open a PR for this.