eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
862 stars 787 forks source link

Fixed possible stop of FW update execution if exception is present #6863

Closed alex-kostadinov closed 5 years ago

alex-kostadinov commented 5 years ago

@kaikreuzer This pull request is a continuation of PR #6859.

Basically, #6859 fixed a possible NPE, but didn't provide a fix for the issue that if an exception occurs the firmware transfer may never continue. Here's the reason why:

Inside processFirmwareStatusInfo(...) the following statement is declared:

 FirmwareStatusInfo previousFirmwareStatusInfo firmwareStatusInfoMap.put(newFirmwareStatusInfo.getThingUID(), newFirmwareStatusInfo);

On one hand, during the first time we set the value for the exact thing UID previousFirmwareStatusInfo is effectively assigned null. On the other hand, however, the value of newFirmwareStatusInfo for the current thing UID is added to the firmwareStatusInfoMap.

Then, inside transferLatestFirmware(...), if an exception occurs, firmwareStatusInfoMap is not changed, because previousFirmwareStatusInfo is null, but at the same time it contains a value of newFirmwareStatusInfo for the current thing UID. Further ahead, e.g. after some time processFirmwareStatusInfo(...) is called again with the same value for newFirmwareStatusInfo, but the check previousFirmwareStatusInfo == null || !previousFirmwareStatusInfo.equals(newFirmwareStatusInfo) is not fulfilled, because previousFirmwareStatusInfo equals newFirmwareStatusInfo and is not null. In this situation, the code that is responsible for transferring the firmware is never executed and the update hangs on.

In order to prevent this, the change done in #6859 is now extended to remove the stored value for the current thing UID from firmwareStatusInfoMap if in case of an exception the previousFirmwareStatusInfo is null.