[tellstick] Fix NPE (#16869) (#16882)

Signed-off-by: Jan Gustafsson <jannegpriv@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jan Gustafsson 2024-06-16 22:13:54 +02:00 committed by Ciprian Pascu
parent d8dd139e47
commit 8137681c3a
2 changed files with 6 additions and 4 deletions

View File

@ -111,7 +111,7 @@ public class TelldusLocalBridgeHandler extends BaseBridgeHandler implements Tell
throws TellstickException, InterruptedException {
TellstickLocalDevicesDTO newList = controller
.callRestMethod(TelldusLocalDeviceController.HTTP_LOCAL_API_DEVICES, TellstickLocalDevicesDTO.class);
if (newList.getDevices() != null) {
if (newList != null && newList.getDevices() != null) {
logger.debug("Device list {}", newList.getDevices());
if (previouslist == null) {
for (TellstickLocalDeviceDTO device : newList.getDevices()) {
@ -167,8 +167,8 @@ public class TelldusLocalBridgeHandler extends BaseBridgeHandler implements Tell
throws TellstickException, InterruptedException {
TellstickLocalSensorsDTO newList = controller
.callRestMethod(TelldusLocalDeviceController.HTTP_LOCAL_API_SENSORS, TellstickLocalSensorsDTO.class);
logger.debug("Updated sensors:{}", newList.getSensors());
if (newList.getSensors() != null) {
if (newList != null && newList.getSensors() != null) {
logger.debug("Updated sensors:{}", newList.getSensors());
if (previouslist == null) {
this.sensorList = newList;
for (TellstickLocalSensorDTO sensor : sensorList.getSensors()) {

View File

@ -18,6 +18,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
@ -249,7 +250,8 @@ public class TelldusLocalDeviceController implements DeviceChangeListener, Senso
setLastSend(newDevices.getTimestamp());
}
<T> T callRestMethod(String uri, Class<T> response) throws TelldusLocalException, InterruptedException {
<T> @Nullable T callRestMethod(String uri, Class<T> response) throws TelldusLocalException, InterruptedException {
@Nullable
T resultObj = null;
try {
for (int i = 0; i < MAX_RETRIES; i++) {