From fddacb4c801bce99461d5f9bef517128c088b21c Mon Sep 17 00:00:00 2001 From: lsiepel Date: Fri, 3 Nov 2023 22:51:23 +0100 Subject: [PATCH] Warning and codeanalysis (#15828) Signed-off-by: Leo Siepel --- .../org/openhab/binding/bluetooth/BluetoothUtils.java | 10 ++++------ .../discovery/internal/BluetoothDeviceSnapshot.java | 1 - .../discovery/internal/BluetoothDiscoveryService.java | 4 +++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/BluetoothUtils.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/BluetoothUtils.java index 2b75d3376..33c9e8b32 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/BluetoothUtils.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/BluetoothUtils.java @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class BluetoothUtils { - public static final Logger logger = LoggerFactory.getLogger(BluetoothUtils.class); + public static final Logger LOGGER = LoggerFactory.getLogger(BluetoothUtils.class); public static final int FORMAT_UINT8 = 0x11; public static final int FORMAT_UINT16 = 0x12; @@ -47,9 +47,7 @@ public class BluetoothUtils { */ public static int[] toIntArray(byte[] value) { int[] ret = new int[value.length]; - for (int i = 0; i < value.length; i++) { - ret[i] = value[i]; - } + System.arraycopy(value, 0, ret, 0, value.length); return ret; } @@ -90,7 +88,7 @@ public class BluetoothUtils { return unsignedToSigned( unsignedBytesToInt(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]), 32); default: - logger.error("Unknown format type {} - no int value can be provided for it.", formatType); + LOGGER.error("Unknown format type {} - no int value can be provided for it.", formatType); } return null; @@ -111,7 +109,7 @@ public class BluetoothUtils { case FORMAT_FLOAT: return bytesToFloat(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]); default: - logger.error("Unknown format type {} - no float value can be provided for it.", formatType); + LOGGER.error("Unknown format type {} - no float value can be provided for it.", formatType); } return null; diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDeviceSnapshot.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDeviceSnapshot.java index b8537c4f6..915611d24 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDeviceSnapshot.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDeviceSnapshot.java @@ -165,7 +165,6 @@ public class BluetoothDeviceSnapshot extends BluetoothDiscoveryDevice { return result; } - @SuppressWarnings("PMD.SimplifyBooleanReturns") @Override public boolean equals(@Nullable Object obj) { if (this == obj) { diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java index 129873f0e..85c530b33 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java @@ -153,7 +153,9 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen logger.debug("Discovered bluetooth device '{}': {}", device.getName(), device); DiscoveryCache cache = discoveryCaches.computeIfAbsent(device.getAddress(), addr -> new DiscoveryCache()); - cache.handleDiscovery(device); + if (cache != null) { + cache.handleDiscovery(device); + } } private static ThingUID createThingUIDWithBridge(DiscoveryResult result, BluetoothAdapter adapter) {