From ba4c96d99dc4c801f0ec19023f242ccf6ab816d1 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Thu, 12 Nov 2020 21:07:11 +0100 Subject: [PATCH] [infrastructure] move infered nullness warnings to error and update EEA (#8949) Signed-off-by: Jan N. Klug --- .../ChannelHandlerAnnouncement.java | 3 +- .../internal/handler/AccountHandler.java | 2 +- .../jsons/JsonRegisterAppRequest.java | 3 +- .../internal/processor/RemoteSensor.java | 3 ++ .../astro/internal/util/PropertyUtils.java | 8 ++- .../internal/RoamingBluetoothDevice.java | 3 +- .../internal/RoamingBridgeHandler.java | 5 +- .../AbstractBluetoothBridgeHandler.java | 3 +- .../bluetooth/MockBluetoothAdapter.java | 3 +- .../internal/BsbLanBindingConstants.java | 12 +---- .../bsblan/internal/BsbLanHandlerFactory.java | 10 +--- .../account/SmartherAuthorizationServlet.java | 7 +-- .../internal/api/SmartherApi.java | 11 ++++- .../internal/handler/ThingHandlerPanel.java | 4 +- .../netutils/WebSocketConnection.java | 5 +- .../internal/types/GroupTypeDeserializer.java | 7 ++- .../internal/types/LightTypeDeserializer.java | 7 ++- .../types/ResourceTypeDeserializer.java | 7 ++- .../types/ThermostatModeGsonTypeAdapter.java | 15 ++---- .../internal/handler/DigiplexAreaHandler.java | 4 +- .../internal/handler/DigiplexZoneHandler.java | 4 +- .../discovery/BridgeDiscoveryService.java | 3 +- .../BridgeMDNSDiscoveryParticipant.java | 3 +- .../discovery/DSMRMeterDiscoveryService.java | 11 ++--- .../internal/data/DwdWarningsData.java | 3 +- .../ecobee/internal/action/EcobeeActions.java | 4 ++ .../ecobee/internal/dto/SelectionDTO.java | 10 ++-- .../internal/stick/TransmitterStick.java | 2 +- .../AbstractFMIResponseParsingTest.java | 7 +-- .../foobot/internal/FoobotApiConnector.java | 4 +- .../handler/FoobotDeviceHandlerTest.java | 2 + .../test/FSInternetRadioHandlerJavaTest.java | 6 +-- .../test/RadioServiceDummy.java | 3 +- .../internal/message/MessageUtil.java | 2 +- .../binding/gree/internal/GreeException.java | 7 ++- .../discovery/GreeDiscoveryService.java | 2 +- .../gree/internal/handler/GreeHandler.java | 8 +-- .../discovery/HarmonyHubDiscoveryService.java | 5 +- .../internal/handler/HeosBridgeHandler.java | 4 +- .../heos/internal/json/HeosJsonParser.java | 3 +- .../binding/hue/internal/HueBridge.java | 27 ++++++++-- .../discovery/HueBridgeNupnpDiscovery.java | 13 ++--- .../internal/HydrawiseCloudHandler.java | 4 +- .../hydrawise/internal/HydrawiseHandler.java | 7 ++- .../internal/api/HydrawiseCloudApiClient.java | 11 +++-- .../internal/api/HydrawiseLocalApiClient.java | 3 +- .../internal/api/IAqualinkClient.java | 30 +++++------- .../internal/handler/InnogyBridgeHandler.java | 12 +++-- .../internal/device/CommandHandler.java | 2 +- .../internal/device/DeviceFeature.java | 11 ++--- .../internal/device/DeviceTypeLoader.java | 24 +++++---- .../handler/InsteonDeviceHandler.java | 10 +--- .../handler/JablotronJa100Handler.java | 4 ++ .../binding/km200/internal/KM200Utils.java | 14 ++++-- .../KM200SwitchProgramServiceHandler.java | 2 +- .../internal/handler/KM200ThingHandler.java | 28 ++++++++--- .../kvv/internal/KVVBridgeHandler.java | 8 ++- .../CustomizedTypeAdapterFactory.java | 4 ++ .../lcn/internal/connection/Connection.java | 9 +--- .../connection/ConnectionStateConnecting.java | 7 ++- .../handler/command/ServiceCommand.java | 5 +- .../handler/command/ServiceSubscription.java | 3 +- .../internal/handler/LifxLightHandler.java | 1 + .../linky/internal/api/EnedisHttpApi.java | 2 +- .../loxone/internal/LxServerHandler.java | 8 +-- .../internal/handler/HTTPHandler.java | 3 +- .../internal/HTTPHandlerEvalTest.java | 4 ++ .../internal/HTTPHandlerValueTest.java | 5 ++ .../discovery/LeapDeviceDiscoveryService.java | 8 +-- .../protocol/leap/LeapMessageParser.java | 4 +- .../internal/handler/MagentaTVControl.java | 5 +- .../internal/handler/MeteoAlerteHandler.java | 7 ++- .../internal/handler/MiIoBasicHandler.java | 4 +- .../handler/ModbusDataThingHandler.java | 10 ++-- .../mapping/MqttTopicClassMapperTests.java | 7 ++- .../internal/BaseChannelConfiguration.java | 3 +- ...hannelConfigurationTypeAdapterFactory.java | 14 ++---- .../handler/NanoleafControllerHandler.java | 7 ++- .../binding/neeo/internal/NeeoBrainApi.java | 12 ++--- .../internal/handler/NeeoBrainHandler.java | 2 +- .../internal/NeohubBoolDeserializer.java | 17 +++---- .../internal/update/NestUpdateHandler.java | 10 ++-- .../webhook/WelcomeWebHookServlet.java | 3 +- .../nhc1/NikoHomeControlCommunication1.java | 25 ++++++++-- .../nhc2/NikoHomeControlCommunication2.java | 21 ++++---- .../ntp/internal/handler/NtpHandler.java | 8 +-- .../nuki/internal/NukiHandlerFactory.java | 6 +-- .../internal/dataexchange/NukiHttpClient.java | 17 +++---- .../internal/handler/StopHandler.java | 22 ++++----- .../handler/BAE091xSensorThingHandler.java | 2 +- .../pixometer/handler/MeterHandler.java | 3 +- .../rest/RemoteopenhabRestClient.java | 5 +- .../revogi/internal/api/StatusService.java | 3 +- .../revogi/internal/api/SwitchService.java | 3 +- .../RFXComDeviceDiscoveryService.java | 4 ++ .../communication/RotelConnector.java | 2 +- .../communication/RotelSimuConnector.java | 6 +-- .../internal/service/MainTVServerService.java | 6 +-- .../internal/event/IntegraStateEvent.java | 5 +- .../senechome/internal/SenecHomeApi.java | 3 +- .../senechome/internal/SenecHomeHandler.java | 49 ++++++++++++------- .../handler/SensiboAccountHandler.java | 9 ++-- .../internal/api/ShellyDeviceProfile.java | 3 +- .../internal/coap/ShellyCoapHandler.java | 6 +-- .../siemensrds/points/PointDeserializer.java | 8 +-- .../internal/SmartMeterHandler.java | 10 ++-- .../internal/conformity/Conformity.java | 40 ++++++++------- .../internal/SmartthingsHandlerFactory.java | 6 ++- .../SmartthingsDiscoveryService.java | 9 ++-- .../binding/smhi/internal/SmhiHandler.java | 10 ++-- .../handler/SomfyMyLinkBridgeHandler.java | 7 +-- .../handler/SomfyTahomaBaseThingHandler.java | 5 +- .../spotify/internal/api/SpotifyApi.java | 3 +- .../internal/builder/ZoneSettingsBuilder.java | 7 ++- .../internal/handler/TadoHomeHandler.java | 3 +- .../internal/handler/TadoZoneHandler.java | 5 +- .../handler/TradfriGatewayHandler.java | 9 ++-- .../internal/handler/VelbusThingHandler.java | 4 +- .../handler/VenstarThermostatHandler.java | 10 +--- .../internal/handler/VigiCruesHandler.java | 10 ++-- .../volvooncall/internal/api/VocHttpApi.java | 3 +- .../WeatherCompanyForecastHandler.java | 3 +- .../WeatherCompanyObservationsHandler.java | 4 +- .../internal/WlanThermoMiniHandler.java | 3 +- .../internal/WlanThermoNanoHandler.java | 5 +- .../accessories/HomekitAccessoryFactory.java | 12 ++--- .../io/hueemulation/internal/rest/Scenes.java | 2 +- .../hueemulation/internal/rest/Schedules.java | 9 ++-- .../rest/mocks/DummyItemRegistry.java | 20 +++++--- .../rest/mocks/DummyMetadataRegistry.java | 14 ++++-- .../rest/mocks/DummyRuleRegistry.java | 14 ++++-- .../org/openhab/io/neeo/internal/NeeoApi.java | 2 +- .../openhab/io/neeo/internal/NeeoUtil.java | 7 ++- .../internal/OpenHabToDeviceConverter.java | 13 +++-- .../openhab/io/neeo/internal/TokenSearch.java | 2 +- .../serialization/ChannelUIDSerializer.java | 8 +-- .../serialization/ItemSubTypeSerializer.java | 15 ++---- .../serialization/ListUiActionSerializer.java | 16 ++---- .../NeeoBrainDeviceSerializer.java | 8 +-- .../NeeoCapabilityTypeSerializer.java | 16 ++---- .../NeeoDeviceChannelKindSerializer.java | 16 ++---- .../NeeoDeviceChannelSerializer.java | 16 ++---- .../serialization/NeeoDeviceSerializer.java | 8 +-- .../NeeoDeviceTypeSerializer.java | 16 ++---- .../serialization/NeeoThingUIDSerializer.java | 16 ++---- .../BrainDashboardService.java | 45 ++++++++++------- .../NeeoBrainSearchService.java | 5 +- .../internal/DynamoDBPersistenceService.java | 2 +- ...AbstractDynamoDBItemSerializationTest.java | 3 ++ .../mapdb/StateTypeAdapterTest.java | 3 +- .../internal/charts/RRD4jChartServlet.java | 9 ++-- bundles/pom.xml | 4 +- .../modbus/tests/ModbusDataHandlerTest.java | 7 +-- itests/pom.xml | 2 +- pom.xml | 5 +- 155 files changed, 644 insertions(+), 632 deletions(-) diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java index 6838f72cf9f..d6bac77128c 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java @@ -14,6 +14,7 @@ package org.openhab.binding.amazonechocontrol.internal.channelhandler; import java.io.IOException; import java.net.URISyntaxException; +import java.util.Objects; import org.apache.commons.lang.StringEscapeUtils; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -91,7 +92,7 @@ public class ChannelHandlerAnnouncement extends ChannelHandler { body = e.getLocalizedMessage(); } } - thingHandler.startAnnouncment(device, speak, body, title, volume); + thingHandler.startAnnouncment(device, speak, Objects.requireNonNullElse(body, ""), title, volume); } refreshChannel(); } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java index fc52d294aca..f3c2497b90a 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java @@ -673,7 +673,7 @@ public class AccountHandler extends BaseBridgeHandler implements IWebSocketComma public void setEnabledFlashBriefingsJson(String flashBriefingJson) { Connection currentConnection = connection; JsonFeed[] feeds = gson.fromJson(flashBriefingJson, JsonFeed[].class); - if (currentConnection != null) { + if (currentConnection != null && feeds != null) { try { currentConnection.setEnabledFlashBriefings(feeds); } catch (IOException | URISyntaxException e) { diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/jsons/JsonRegisterAppRequest.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/jsons/JsonRegisterAppRequest.java index 5e3a7d629c7..9bbae05dc63 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/jsons/JsonRegisterAppRequest.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/jsons/JsonRegisterAppRequest.java @@ -25,7 +25,8 @@ import com.google.gson.annotations.SerializedName; @NonNullByDefault public class JsonRegisterAppRequest { - public JsonRegisterAppRequest(String serial, String accessToken, String frc, JsonWebSiteCookie[] webSiteCookies) { + public JsonRegisterAppRequest(String serial, @Nullable String accessToken, String frc, + JsonWebSiteCookie[] webSiteCookies) { registrationData.deviceSerial = serial; authData.accessToken = accessToken; userContextMap.frc = frc; diff --git a/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/processor/RemoteSensor.java b/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/processor/RemoteSensor.java index f2e2dccd3b4..865e6e51767 100644 --- a/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/processor/RemoteSensor.java +++ b/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/processor/RemoteSensor.java @@ -73,6 +73,9 @@ public class RemoteSensor { * there are remote sensor values */ private void updateSensorChannels(AmbientWeatherStationHandler handler, int i, final @Nullable String jsonData) { + if (jsonData == null) { + return; + } String sensorNumber = String.valueOf(i); StringReader stringReader = new StringReader(jsonData); JsonReader reader = new JsonReader(stringReader); diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java index e2cf730ffe0..355edeb7328 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java @@ -19,6 +19,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Objects; import java.util.TimeZone; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -91,11 +92,8 @@ public class PropertyUtils { Method m = instance.getClass().getMethod(toGetterString(propertyName), null); Object result = m.invoke(instance, (Object[]) null); if (nestedIndex + 1 < properties.length) { - if (result != null) { - return getPropertyValue(result, properties, nestedIndex + 1); - } else { - throw new NullPointerException(); - } + Objects.requireNonNull(result); + return getPropertyValue(result, properties, nestedIndex + 1); } return result; } diff --git a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBluetoothDevice.java b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBluetoothDevice.java index e992d4a43ba..98251ae0f76 100644 --- a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBluetoothDevice.java +++ b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBluetoothDevice.java @@ -15,6 +15,7 @@ package org.openhab.binding.bluetooth.roaming.internal; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; @@ -52,7 +53,7 @@ public class RoamingBluetoothDevice extends DelegateBluetoothDevice { } public void addBluetoothDevice(BluetoothDevice device) { - device.addListener(devices.computeIfAbsent(device, Listener::new)); + device.addListener(Objects.requireNonNull(devices.computeIfAbsent(device, Listener::new))); } public void removeBluetoothDevice(BluetoothDevice device) { diff --git a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java index 75e62114ae6..4172c4f3c8d 100644 --- a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java +++ b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java @@ -14,6 +14,7 @@ package org.openhab.binding.bluetooth.roaming.internal; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; import java.util.stream.Stream; @@ -216,8 +217,8 @@ public class RoamingBridgeHandler extends BaseBridgeHandler implements RoamingBl public RoamingBluetoothDevice getDevice(BluetoothAddress address) { // this will only get called by a bluetooth device handler synchronized (devices) { - RoamingBluetoothDevice roamingDevice = devices.computeIfAbsent(address, - addr -> new RoamingBluetoothDevice(this, addr)); + RoamingBluetoothDevice roamingDevice = Objects + .requireNonNull(devices.computeIfAbsent(address, addr -> new RoamingBluetoothDevice(this, addr))); adapters.stream().filter(this::isRoamingMember) .forEach(adapter -> roamingDevice.addBluetoothDevice(adapter.getDevice(address))); diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/AbstractBluetoothBridgeHandler.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/AbstractBluetoothBridgeHandler.java index 9f8ce9d6618..c76e56c3e5f 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/AbstractBluetoothBridgeHandler.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/AbstractBluetoothBridgeHandler.java @@ -14,6 +14,7 @@ package org.openhab.binding.bluetooth; import java.time.ZonedDateTime; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; @@ -186,7 +187,7 @@ public abstract class AbstractBluetoothBridgeHandler new MockBluetoothDevice(this, addr)); + return Objects.requireNonNull(devices.computeIfAbsent(address, addr -> new MockBluetoothDevice(this, addr))); } @Override diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanBindingConstants.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanBindingConstants.java index 28c926fc185..6aacb84a676 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanBindingConstants.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bsblan.internal; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -42,15 +41,8 @@ public class BsbLanBindingConstants { public static final String PARAMETER_CHANNEL_DESCRIPTION = "description"; public static final String PARAMETER_CHANNEL_DATATYPE = "datatype"; - public static final Set WRITEABLE_CHANNELS = new HashSet() { - - private static final long serialVersionUID = 1L; - { - add(PARAMETER_CHANNEL_NUMBER_VALUE); - add(PARAMETER_CHANNEL_STRING_VALUE); - add(PARAMETER_CHANNEL_SWITCH_VALUE); - } - }; + public static final Set WRITEABLE_CHANNELS = Set.of(PARAMETER_CHANNEL_NUMBER_VALUE, + PARAMETER_CHANNEL_STRING_VALUE, PARAMETER_CHANNEL_SWITCH_VALUE); public static final int MIN_REFRESH_INTERVAL = 5; public static final int DEFAULT_REFRESH_INTERVAL = 60; diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanHandlerFactory.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanHandlerFactory.java index 68c3e7992af..78176291ef9 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanHandlerFactory.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/BsbLanHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.bsblan.internal; import static org.openhab.binding.bsblan.internal.BsbLanBindingConstants.*; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -39,14 +38,7 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.bsblan") public class BsbLanHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet() { - - private static final long serialVersionUID = 1L; - { - add(THING_TYPE_PARAMETER); - add(THING_TYPE_BRIDGE); - } - }; + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PARAMETER, THING_TYPE_BRIDGE); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/account/SmartherAuthorizationServlet.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/account/SmartherAuthorizationServlet.java index 35b165f045c..80752aa5554 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/account/SmartherAuthorizationServlet.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/account/SmartherAuthorizationServlet.java @@ -142,9 +142,10 @@ public class SmartherAuthorizationServlet extends HttpServlet { final StringBuffer requestURL = request.getRequestURL(); // Try to infer the real protocol from request headers - final String realProtocol = StringUtil.defaultIfBlank(request.getHeader(X_FORWARDED_PROTO), - request.getScheme()); - + String realProtocol = request.getHeader(X_FORWARDED_PROTO); + if (realProtocol == null || realProtocol.isBlank()) { + realProtocol = request.getScheme(); + } return requestURL.replace(0, requestURL.indexOf(":"), realProtocol).toString(); } diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApi.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApi.java index 99cd23eca03..cb0066f6218 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApi.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApi.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Function; @@ -177,7 +178,9 @@ public class SmartherApi { public ModuleStatus getModuleStatus(String plantId, String moduleId) throws SmartherGatewayException { try { final ContentResponse response = requestModule(GET, plantId, moduleId, null); - return ModelUtil.gsonInstance().fromJson(response.getContentAsString(), ModuleStatus.class); + ModuleStatus moduleStatus = ModelUtil.gsonInstance().fromJson(response.getContentAsString(), + ModuleStatus.class); + return Objects.requireNonNull(moduleStatus); } catch (JsonSyntaxException e) { throw new SmartherGatewayException(e.getMessage()); } @@ -280,9 +283,13 @@ public class SmartherApi { if (response.getStatus() == HttpStatus.NO_CONTENT_204) { return new ArrayList<>(); } else { - return ModelUtil.gsonInstance().fromJson(response.getContentAsString(), + List subscriptions = ModelUtil.gsonInstance().fromJson(response.getContentAsString(), new TypeToken>() { }.getType()); + if (subscriptions == null) { + throw new SmartherGatewayException("fromJson returned null"); + } + return subscriptions; } } catch (JsonSyntaxException e) { throw new SmartherGatewayException(e.getMessage()); diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java index a79c62d00e7..fd8e0520c7b 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java @@ -165,8 +165,8 @@ public class ThingHandlerPanel extends CaddxBaseThingHandler { // get the channel id from the map HashMap logMap = panelLogMessagesMap; - if (logMap != null && logMap.containsKey(eventNumberString)) { - String id = logMap.get(eventNumberString); + String id = logMap.get(eventNumberString); + if (logMap != null && id != null) { ChannelUID channelUID = new ChannelUID(getThing().getUID(), id); updateChannel(channelUID, logEventMessage.toString()); } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/netutils/WebSocketConnection.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/netutils/WebSocketConnection.java index d8d7a923add..703276d08c8 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/netutils/WebSocketConnection.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/netutils/WebSocketConnection.java @@ -131,7 +131,10 @@ public class WebSocketConnection { return; } - listener.messageReceived(changedMessage.id, gson.fromJson(message, expectedMessageType)); + DeconzBaseMessage deconzMessage = gson.fromJson(message, expectedMessageType); + if (deconzMessage != null) { + listener.messageReceived(changedMessage.id, deconzMessage); + } } @OnWebSocketError diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/GroupTypeDeserializer.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/GroupTypeDeserializer.java index 3bb2c1db277..de82d7ebd27 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/GroupTypeDeserializer.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/GroupTypeDeserializer.java @@ -30,9 +30,8 @@ import com.google.gson.JsonParseException; @NonNullByDefault public class GroupTypeDeserializer implements JsonDeserializer { @Override - public GroupType deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - String s = json != null ? json.getAsString() : null; - return s == null ? GroupType.UNKNOWN : GroupType.fromString(s); + public @Nullable GroupType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return GroupType.fromString(json.getAsString()); } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/LightTypeDeserializer.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/LightTypeDeserializer.java index 8255feb12e0..9bb8e1db2e5 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/LightTypeDeserializer.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/LightTypeDeserializer.java @@ -30,9 +30,8 @@ import com.google.gson.JsonParseException; @NonNullByDefault public class LightTypeDeserializer implements JsonDeserializer { @Override - public LightType deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - String s = json != null ? json.getAsString() : null; - return s == null ? LightType.UNKNOWN : LightType.fromString(s); + public @Nullable LightType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return LightType.fromString(json.getAsString()); } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ResourceTypeDeserializer.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ResourceTypeDeserializer.java index b8f6e211a4c..a73dcdc9fe7 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ResourceTypeDeserializer.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ResourceTypeDeserializer.java @@ -30,9 +30,8 @@ import com.google.gson.JsonParseException; @NonNullByDefault public class ResourceTypeDeserializer implements JsonDeserializer { @Override - public ResourceType deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - String s = json != null ? json.getAsString() : null; - return s == null ? ResourceType.UNKNOWN : ResourceType.fromString(s); + public @Nullable ResourceType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return ResourceType.fromString(json.getAsString()); } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ThermostatModeGsonTypeAdapter.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ThermostatModeGsonTypeAdapter.java index 652a2e13d75..ff08ad67387 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ThermostatModeGsonTypeAdapter.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/types/ThermostatModeGsonTypeAdapter.java @@ -34,19 +34,14 @@ import com.google.gson.JsonSerializer; @NonNullByDefault public class ThermostatModeGsonTypeAdapter implements JsonDeserializer, JsonSerializer { @Override - public ThermostatMode deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - JsonElement jsonLocal = json; - if (jsonLocal != null) { - String s = jsonLocal.getAsString(); - return s == null ? ThermostatMode.UNKNOWN : ThermostatMode.fromString(s); - } - return ThermostatMode.UNKNOWN; + public @Nullable ThermostatMode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return ThermostatMode.fromString(json.getAsString()); } @Override - public JsonElement serialize(ThermostatMode src, @Nullable Type typeOfSrc, - @Nullable JsonSerializationContext context) throws JsonParseException { + public JsonElement serialize(ThermostatMode src, Type typeOfSrc, JsonSerializationContext context) + throws JsonParseException { return src != ThermostatMode.UNKNOWN ? new JsonPrimitive(src.getDeconzValue()) : JsonNull.INSTANCE; } } diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java index e29aa43ad1b..39af1b96acc 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java @@ -163,7 +163,9 @@ public class DigiplexAreaHandler extends BaseThingHandler { bridgeHandler = (DigiplexBridgeHandler) bridge.getHandler(); String areaParm = getThing().getProperties().get(DigiplexBindingConstants.PROPERTY_AREA_NO); - areaNo = Integer.parseInt(areaParm); + if (areaParm != null) { + areaNo = Integer.parseInt(areaParm); + } bridgeHandler.registerMessageHandler(visitor); updateStatus(ThingStatus.ONLINE); diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexZoneHandler.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexZoneHandler.java index 8bb308c6046..33bb288ccef 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexZoneHandler.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexZoneHandler.java @@ -121,7 +121,9 @@ public class DigiplexZoneHandler extends BaseThingHandler { this.bridgeHandler = (DigiplexBridgeHandler) bridge.getHandler(); String nodeParm = getThing().getProperties().get(DigiplexBindingConstants.PROPERTY_ZONE_NO); - zoneNo = Integer.parseInt(nodeParm); + if (nodeParm != null) { + zoneNo = Integer.parseInt(nodeParm); + } String areaParm = getThing().getProperties().get(DigiplexBindingConstants.PROPERTY_AREA_NO); if (areaParm != null) { areaNo = Integer.parseInt(areaParm); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeDiscoveryService.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeDiscoveryService.java index 66f87f94d85..92e04ef036e 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeDiscoveryService.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeDiscoveryService.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants; import org.openhab.binding.digitalstrom.internal.lib.config.Config; import org.openhab.binding.digitalstrom.internal.lib.serverconnection.DsAPI; @@ -81,7 +80,7 @@ public class BridgeDiscoveryService extends AbstractDiscoveryService { if (dsidMap != null) { dSID = dsidMap.get(JSONApiResponseKeysEnum.DSID.getKey()); } - if (StringUtils.isNotBlank(dSID)) { + if (dSID != null && !dSID.isBlank()) { return new ThingUID(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE, dSID); } else { logger.error("Can't get server dSID to generate ThingUID. Please add the server manually."); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java index a54cd9b9ec5..122aac5d0d2 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java @@ -19,7 +19,6 @@ import java.util.Set; import javax.jmdns.ServiceInfo; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants; import org.openhab.binding.digitalstrom.internal.lib.config.Config; import org.openhab.binding.digitalstrom.internal.lib.serverconnection.DsAPI; @@ -84,7 +83,7 @@ public class BridgeMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant if (dsidMap != null) { dSID = dsidMap.get(JSONApiResponseKeysEnum.DSID.getKey()); } - if (StringUtils.isNotBlank(dSID)) { + if (dSID != null && !dSID.isBlank()) { return new ThingUID(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE, dSID); } else { logger.error("Can't get server dSID to generate thing UID. Please add the server manually."); diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java index 18392b1146c..b1f2dd41c52 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java @@ -12,12 +12,8 @@ */ package org.openhab.binding.dsmr.internal.discovery; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -148,8 +144,9 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P .filter(DSMRMeterHandler.class::isInstance) .map(DSMRMeterHandler.class::cast) .map(h -> h == null ? null : h.getMeterDescriptor()) - .map(d -> d == null ? null : d.getMeterType()) - .filter(Objects::nonNull) + .map(d -> Optional.ofNullable(d == null ? null : d.getMeterType())) + .filter(Optional::isPresent) + .map(Optional::get) .collect(Collectors.toSet()); // @formatter:on // Create list of all configured meters that are not in the detected list. If not empty meters might not be diff --git a/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/data/DwdWarningsData.java b/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/data/DwdWarningsData.java index ac47d4e9104..354283bdf1a 100644 --- a/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/data/DwdWarningsData.java +++ b/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/data/DwdWarningsData.java @@ -32,7 +32,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; -import org.apache.commons.lang.StringUtils; import org.openhab.core.cache.ExpiringCache; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.OnOffType; @@ -111,7 +110,7 @@ public class DwdWarningsData { */ public boolean refresh() { String rawData = dataAccessCached.getValue(); - if (StringUtils.isEmpty(rawData)) { + if (rawData == null || rawData.isEmpty()) { logger.debug("No Data from Endpoint"); return false; } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java index 911d53d9e0e..e47fdabd411 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java @@ -414,6 +414,10 @@ public class EcobeeActions implements ThingActions { EventDTO event = new EventDTO(); for (String key : params.keySet()) { Object value = params.get(key); + if (value == null) { + LOGGER.warn("Event field '{}' has null value, ignored.", key); + continue; + } switch (key) { case "isOccupied": event.isOccupied = ((Boolean) value); diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/dto/SelectionDTO.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/dto/SelectionDTO.java index e4c7ddb8971..a539791f0d0 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/dto/SelectionDTO.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/dto/SelectionDTO.java @@ -165,9 +165,13 @@ public class SelectionDTO { } public void setThermostats(Set thermostatIds) { - boolean isRegistered = thermostatIds == null || thermostatIds.isEmpty(); - selectionType = isRegistered ? SelectionType.REGISTERED : SelectionType.THERMOSTATS; - selectionMatch = isRegistered ? "" : String.join(",", thermostatIds); + if (thermostatIds == null || thermostatIds.isEmpty()) { + selectionType = SelectionType.REGISTERED; + selectionMatch = ""; + } else { + selectionType = SelectionType.THERMOSTATS; + selectionMatch = String.join(",", thermostatIds); + } } public void setSelectionType(SelectionType selectionType) { diff --git a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java index 166084ff968..a7e2bd1e6d3 100644 --- a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java +++ b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java @@ -159,7 +159,7 @@ public class TransmitterStick { private static final long serialVersionUID = -3216360253151368826L; public DueCommandSet() { - super(new Comparator() { + super(new Comparator<>() { /** * Due commands are sorted by priority first and then by delay. */ diff --git a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractFMIResponseParsingTest.java b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractFMIResponseParsingTest.java index 832aac0f2f5..121237b3508 100644 --- a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractFMIResponseParsingTest.java +++ b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractFMIResponseParsingTest.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Objects; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -123,7 +124,7 @@ public class AbstractFMIResponseParsingTest { try { Method parseMethod = Client.class.getDeclaredMethod("parseMultiPointCoverageXml", String.class); parseMethod.setAccessible(true); - return (FMIResponse) parseMethod.invoke(client, content); + return Objects.requireNonNull((FMIResponse) parseMethod.invoke(client, content)); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (Exception e) { @@ -137,9 +138,9 @@ public class AbstractFMIResponseParsingTest { @SuppressWarnings("unchecked") protected Set parseStations(String content) { try { - Method parseMethod = Client.class.getDeclaredMethod("parseStations", String.class); + Method parseMethod = Objects.requireNonNull(Client.class.getDeclaredMethod("parseStations", String.class)); parseMethod.setAccessible(true); - return (Set) parseMethod.invoke(client, content); + return Objects.requireNonNull((Set) parseMethod.invoke(client, content)); } catch (InvocationTargetException e) { throw new RuntimeException(e.getTargetException()); } catch (Exception e) { diff --git a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotApiConnector.java b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotApiConnector.java index 4f089fdf486..9dab3306c77 100644 --- a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotApiConnector.java +++ b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotApiConnector.java @@ -20,6 +20,7 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -95,7 +96,8 @@ public class FoobotApiConnector { URLEncoder.encode(username, StandardCharsets.UTF_8.toString())); logger.debug("URL = {}", url); - return GSON.fromJson(request(url, apiKey), FOOTBOT_DEVICE_LIST_TYPE); + List foobotDevices = GSON.fromJson(request(url, apiKey), FOOTBOT_DEVICE_LIST_TYPE); + return Objects.requireNonNull(foobotDevices); } catch (JsonParseException | UnsupportedEncodingException e) { throw new FoobotApiException(0, e.getMessage()); } diff --git a/bundles/org.openhab.binding.foobot/src/test/java/org/openhab/binding/foobot/internal/handler/FoobotDeviceHandlerTest.java b/bundles/org.openhab.binding.foobot/src/test/java/org/openhab/binding/foobot/internal/handler/FoobotDeviceHandlerTest.java index b0f049d905b..77e88c6fb39 100644 --- a/bundles/org.openhab.binding.foobot/src/test/java/org/openhab/binding/foobot/internal/handler/FoobotDeviceHandlerTest.java +++ b/bundles/org.openhab.binding.foobot/src/test/java/org/openhab/binding/foobot/internal/handler/FoobotDeviceHandlerTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Objects; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -53,6 +54,7 @@ public class FoobotDeviceHandlerTest { final FoobotJsonData sensorData = connector.getSensorData("1234"); assertNotNull(sensorData, "No sensor data read"); + Objects.requireNonNull(sensorData); assertEquals(handler.sensorDataToState("temperature", sensorData), new QuantityType(12.345, SIUnits.CELSIUS)); assertEquals(handler.sensorDataToState("gpi", sensorData), new DecimalType(5.6789012)); } diff --git a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java index b4de21d03c6..1c8e34144a6 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java @@ -21,10 +21,7 @@ import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindin import java.io.IOException; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -148,6 +145,7 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest { private static @NonNull Channel getChannel(final @NonNull Thing thing, final @NonNull String channelId) { final Channel channel = thing.getChannel(channelId); assertNotNull(channel); + Objects.requireNonNull(channel); return channel; } diff --git a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/RadioServiceDummy.java b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/RadioServiceDummy.java index c8909b7dcad..ccad8f7f8d1 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/RadioServiceDummy.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/RadioServiceDummy.java @@ -18,6 +18,7 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import javax.servlet.ServletException; @@ -134,7 +135,7 @@ public class RadioServiceDummy extends HttpServlet { Collection requestParameterNames = Collections.list(request.getParameterNames()); if (queryString != null && requestParameterNames.contains(VALUE)) { StringBuffer fullUrl = request.getRequestURL().append("?").append(queryString); - int value = Integer.parseInt(request.getParameter(VALUE)); + int value = Integer.parseInt(Objects.requireNonNullElse(request.getParameter(VALUE), "")); requestParameters.put(value, fullUrl.toString()); } diff --git a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/MessageUtil.java b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/MessageUtil.java index c8fe210aebf..3c017e7f6b2 100644 --- a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/MessageUtil.java +++ b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/MessageUtil.java @@ -51,7 +51,7 @@ public class MessageUtil { public LocationMessage fromJson(String json) { for (String pattern : PATTERNS) { Class c = MESSAGE_TYPES.get(pattern); - if (json.matches(pattern)) { + if (c != null && json.matches(pattern)) { return gson.fromJson(json, c); } } diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeException.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeException.java index bccdd4afcc9..32eadc0abf3 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeException.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeException.java @@ -47,8 +47,7 @@ public class GreeException extends Exception { super(message, exception); } - @Override - public @Nullable String getMessage() { + public String getMessageString() { return isEmpty() ? "" : nonNullString(super.getMessage()); } @@ -69,7 +68,7 @@ public class GreeException extends Exception { message = MessageFormat.format("{0} ({1})", message, cause); } } else { - message = getMessage(); + message = getMessageString(); } return message; } @@ -82,7 +81,7 @@ public class GreeException extends Exception { Class extype = !isEmpty() ? getCauseClass() : null; return (extype != null) && ((extype == SocketTimeoutException.class) || (extype == TimeoutException.class) || (extype == ExecutionException.class) || (extype == InterruptedException.class) - || getMessage().toLowerCase().contains("timeout")); + || getMessageString().toLowerCase().contains("timeout")); } public boolean isUnknownHost() { diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDiscoveryService.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDiscoveryService.java index 0523c5a6419..50244f6a3d5 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDiscoveryService.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDiscoveryService.java @@ -97,7 +97,7 @@ public class GreeDiscoveryService extends AbstractDiscoveryService { createResult(deviceFinder.getDevices()); } } catch (GreeException e) { - logger.info("Discovery: {}", messages.get("discovery.exception", e.getMessage())); + logger.info("Discovery: {}", messages.get("discovery.exception", e.getMessageString())); } catch (SocketException | RuntimeException e) { logger.warn("Discovery: {}", messages.get("discovery.exception", "RuntimeException"), e); } diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java index b6cef937f49..dcb9d41f28f 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java @@ -122,7 +122,7 @@ public class GreeHandler extends BaseThingHandler { message = messages.get("thinginit.failed"); logger.info("{}: {}", thingId, message); } catch (GreeException e) { - logger.info("{}: {}", thingId, messages.get("thinginit.exception", e.getMessage())); + logger.info("{}: {}", thingId, messages.get("thinginit.exception", e.getMessageString())); } catch (IOException e) { logger.warn("{}: {}", thingId, messages.get("thinginit.exception", "I/O Error"), e); } catch (RuntimeException e) { @@ -158,7 +158,7 @@ public class GreeHandler extends BaseThingHandler { logger.debug("{}: Command {} failed for channel {}, retry", thingId, command, channelId); } else { String message = logInfo( - messages.get("command.exception", command, channelId) + ": " + e.getMessage()); + messages.get("command.exception", command, channelId) + ": " + e.getMessageString()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message); } } catch (IllegalArgumentException e) { @@ -379,7 +379,7 @@ public class GreeHandler extends BaseThingHandler { if (e.getCause() != null) { subcode = " (" + e.getCause().getMessage() + ")"; } - String message = messages.get("update.exception", e.getMessage() + subcode); + String message = messages.get("update.exception", e.getMessageString() + subcode); if (getThing().getStatus() == ThingStatus.OFFLINE) { logger.debug("{}: Thing still OFFLINE ({})", thingId, message); } else { @@ -472,7 +472,7 @@ public class GreeHandler extends BaseThingHandler { updateState(channelID, state); } } catch (GreeException e) { - logger.info("{}: {}", thingId, messages.get("channel.exception", channelID, e.getMessage())); + logger.info("{}: {}", thingId, messages.get("channel.exception", channelID, e.getMessageString())); } catch (RuntimeException e) { logger.warn("{}: {}", thingId, messages.get("channel.exception", "RuntimeException"), e); } diff --git a/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/discovery/HarmonyHubDiscoveryService.java b/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/discovery/HarmonyHubDiscoveryService.java index 214c5a5abab..7ea80306aa6 100644 --- a/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/discovery/HarmonyHubDiscoveryService.java +++ b/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/discovery/HarmonyHubDiscoveryService.java @@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.harmonyhub.internal.handler.HarmonyHubHandler; @@ -253,8 +252,8 @@ public class HarmonyHubDiscoveryService extends AbstractDiscoveryService { String friendlyName = properties.get("friendlyName"); String hostName = properties.get("host_name"); String ip = properties.get("ip"); - if (StringUtils.isNotBlank(friendlyName) && StringUtils.isNotBlank(hostName) - && StringUtils.isNotBlank(ip) && !responses.contains(hostName)) { + if (friendlyName != null && !friendlyName.isBlank() && hostName != null && !hostName.isBlank() + && ip != null && !ip.isBlank() && !responses.contains(hostName)) { responses.add(hostName); hubDiscovered(ip, friendlyName, hostName); } diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/handler/HeosBridgeHandler.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/handler/HeosBridgeHandler.java index 7dc62237c4b..03b1a90869a 100644 --- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/handler/HeosBridgeHandler.java +++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/handler/HeosBridgeHandler.java @@ -196,7 +196,9 @@ public class HeosBridgeHandler extends BaseBridgeHandler implements HeosEventLis @Nullable Group[] onlineGroups = getApiConnection().getGroups().payload; - updatePlayerStatus(onlinePlayers, onlineGroups); + if (onlinePlayers != null && onlineGroups != null) { + updatePlayerStatus(onlinePlayers, onlineGroups); + } } catch (ReadException | IOException e) { logger.debug("Failed updating online state of groups/players", e); } diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/json/HeosJsonParser.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/json/HeosJsonParser.java index ad78dd2b667..d2c72887bb3 100644 --- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/json/HeosJsonParser.java +++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/json/HeosJsonParser.java @@ -18,6 +18,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -57,7 +58,7 @@ public class HeosJsonParser { public HeosResponseObject parseResponse(String jsonBody, Class clazz) { HeosJsonWrapper wrapper = gson.fromJson(jsonBody, HeosJsonWrapper.class); - return postProcess(wrapper, clazz); + return postProcess(Objects.requireNonNull(wrapper), clazz); } private HeosResponseObject postProcess(HeosJsonWrapper wrapper, Class clazz) { diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java index 9f981232d2e..463ed8cb70a 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java @@ -359,7 +359,11 @@ public class HueBridge { List entries = safeFromJson(result.getBody(), SuccessResponse.GSON_TYPE); SuccessResponse response = entries.get(0); - return (String) response.success.get("/lights/" + enc(light.getId()) + "/name"); + String lightName = (String) response.success.get("/lights/" + enc(light.getId()) + "/name"); + if (lightName == null) { + throw new ApiException("Response didn't contain light name."); + } + return lightName; } /** @@ -560,7 +564,11 @@ public class HueBridge { List entries = safeFromJson(result.getBody(), SuccessResponse.GSON_TYPE); SuccessResponse response = entries.get(0); - return (String) response.success.get("/groups/" + enc(group.getId()) + "/name"); + String groupName = (String) response.success.get("/groups/" + enc(group.getId()) + "/name"); + if (groupName == null) { + throw new ApiException("Response didn't contain group name."); + } + return groupName; } /** @@ -610,7 +618,11 @@ public class HueBridge { List entries = safeFromJson(result.getBody(), SuccessResponse.GSON_TYPE); SuccessResponse response = entries.get(0); - return (String) response.success.get("/groups/" + enc(group.getId()) + "/name"); + String groupName = (String) response.success.get("/groups/" + enc(group.getId()) + "/name"); + if (groupName == null) { + throw new ApiException("Response didn't contain group name."); + } + return groupName; } /** @@ -955,7 +967,11 @@ public class HueBridge { List entries = safeFromJson(result.getBody(), SuccessResponse.GSON_TYPE); SuccessResponse response = entries.get(0); - return (String) response.success.get("username"); + String username = (String) response.success.get("username"); + if (username == null) { + throw new ApiException("Response didn't contain username"); + } + return username; } /** @@ -1019,7 +1035,8 @@ public class HueBridge { handleErrors(result); - return gson.fromJson(result.getBody(), FullConfig.class); + FullConfig fullConfig = gson.fromJson(result.getBody(), FullConfig.class); + return Objects.requireNonNull(fullConfig); } // Used as assert in requests that require authentication diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeNupnpDiscovery.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeNupnpDiscovery.java index 9f0f8fcfa28..9e19852481f 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeNupnpDiscovery.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeNupnpDiscovery.java @@ -16,12 +16,7 @@ import static org.openhab.binding.hue.internal.HueBindingConstants.*; import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -162,8 +157,10 @@ public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService { try { Gson gson = new Gson(); String json = doGetRequest(DISCOVERY_URL); - return gson.fromJson(json, new TypeToken>() { - }.getType()); + List bridgeParameters = gson.fromJson(json, + new TypeToken>() { + }.getType()); + return Objects.requireNonNull(bridgeParameters); } catch (IOException e) { logger.debug("Philips Hue NUPnP service not reachable. Can't discover bridges"); } catch (JsonParseException je) { diff --git a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseCloudHandler.java b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseCloudHandler.java index 12b6a0358b2..f8391675ba6 100644 --- a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseCloudHandler.java +++ b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseCloudHandler.java @@ -19,7 +19,6 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -94,10 +93,9 @@ public class HydrawiseCloudHandler extends HydrawiseHandler { } else { // try and use ID from saved property String controllerId = getThing().getProperties().get(PROPERTY_CONTROLLER_ID); - if (StringUtils.isNotBlank(controllerId)) { + if (controllerId != null && !controllerId.isBlank()) { try { controller = getController(Integer.parseInt(controllerId), controllers); - } catch (NumberFormatException e) { logger.debug("Can not parse property vaue {}", controllerId); } diff --git a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseHandler.java b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseHandler.java index 42d4e000b1a..40440034587 100644 --- a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseHandler.java +++ b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/HydrawiseHandler.java @@ -16,10 +16,7 @@ import static org.openhab.binding.hydrawise.internal.HydrawiseBindingConstants.* import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -127,6 +124,7 @@ public abstract class HydrawiseHandler extends BaseThingHandler { if (allCommand) { sendRunAllCommand(((DecimalType) command).intValue()); } else { + Objects.requireNonNull(relay); sendRunCommand(((DecimalType) command).intValue(), relay); } break; @@ -142,6 +140,7 @@ public abstract class HydrawiseHandler extends BaseThingHandler { sendStopAllCommand(); } } else { + Objects.requireNonNull(relay); if (command == OnOffType.ON) { sendRunCommand(relay); } else { diff --git a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseCloudApiClient.java b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseCloudApiClient.java index e17ebb6f2c1..8db54db1e1e 100644 --- a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseCloudApiClient.java +++ b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseCloudApiClient.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.hydrawise.internal.api; +import java.util.Objects; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -89,7 +90,7 @@ public class HydrawiseCloudApiClient { public StatusScheduleResponse getStatusSchedule(int controllerId) throws HydrawiseConnectionException, HydrawiseAuthenticationException { String json = doGet(String.format(STATUS_SCHEDUE_URL, apiKey, controllerId)); - StatusScheduleResponse response = gson.fromJson(json, StatusScheduleResponse.class); + StatusScheduleResponse response = Objects.requireNonNull(gson.fromJson(json, StatusScheduleResponse.class)); throwExceptionIfResponseError(response); return response; } @@ -104,13 +105,13 @@ public class HydrawiseCloudApiClient { public CustomerDetailsResponse getCustomerDetails() throws HydrawiseConnectionException, HydrawiseAuthenticationException { String json = doGet(String.format(CUSTOMER_DETAILS_URL, apiKey)); - CustomerDetailsResponse response = gson.fromJson(json, CustomerDetailsResponse.class); + CustomerDetailsResponse response = Objects.requireNonNull(gson.fromJson(json, CustomerDetailsResponse.class)); throwExceptionIfResponseError(response); return response; } /*** - * Sets the controller with supplied {@value id} as the current controller + * Sets the controller with supplied {@param id} as the current controller * * @param id * @return SetControllerResponse @@ -121,7 +122,7 @@ public class HydrawiseCloudApiClient { public SetControllerResponse setController(int id) throws HydrawiseConnectionException, HydrawiseAuthenticationException, HydrawiseCommandException { String json = doGet(String.format(SET_CONTROLLER_URL, apiKey, id)); - SetControllerResponse response = gson.fromJson(json, SetControllerResponse.class); + SetControllerResponse response = Objects.requireNonNull(gson.fromJson(json, SetControllerResponse.class)); throwExceptionIfResponseError(response); if (!response.message.equals("OK")) { throw new HydrawiseCommandException(response.message); @@ -271,7 +272,7 @@ public class HydrawiseCloudApiClient { private String relayCommand(String url) throws HydrawiseConnectionException, HydrawiseAuthenticationException, HydrawiseCommandException { String json = doGet(url); - SetZoneResponse response = gson.fromJson(json, SetZoneResponse.class); + SetZoneResponse response = Objects.requireNonNull(gson.fromJson(json, SetZoneResponse.class)); throwExceptionIfResponseError(response); if ("error".equals(response.messageType)) { throw new HydrawiseCommandException(response.message); diff --git a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseLocalApiClient.java b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseLocalApiClient.java index d76467002fd..3c2de22e600 100644 --- a/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseLocalApiClient.java +++ b/bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/api/HydrawiseLocalApiClient.java @@ -13,6 +13,7 @@ package org.openhab.binding.hydrawise.internal.api; import java.net.URI; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -95,7 +96,7 @@ public class HydrawiseLocalApiClient { throws HydrawiseConnectionException, HydrawiseAuthenticationException { String json = doGet(localGetURL); LocalScheduleResponse response = gson.fromJson(json, LocalScheduleResponse.class); - return response; + return Objects.requireNonNull(response); } /** diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java index 604593ba7ab..d407f1ced13 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java @@ -17,6 +17,7 @@ import java.lang.reflect.Type; import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -120,7 +121,7 @@ public class IAqualinkClient { if (response.getStatus() != HttpStatus.OK_200) { throw new IOException(response.getReason()); } - return gson.fromJson(response.getContentAsString(), AccountInfo.class); + return Objects.requireNonNull(gson.fromJson(response.getContentAsString(), AccountInfo.class)); } catch (InterruptedException | TimeoutException | ExecutionException e) { throw new IOException(e); } @@ -347,7 +348,7 @@ public class IAqualinkClient { * @throws NotAuthorizedException */ private T getAqualinkObject(URI uri, Type typeOfT) throws IOException, NotAuthorizedException { - return gson.fromJson(getRequest(uri), typeOfT); + return Objects.requireNonNull(gson.fromJson(getRequest(uri), typeOfT)); } /** @@ -383,11 +384,8 @@ public class IAqualinkClient { class HomeDeserializer implements JsonDeserializer { @Override - public Home deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - if (json == null) { - throw new JsonParseException("No JSON"); - } + public @Nullable Home deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonArray homeScreen = jsonObject.getAsJsonArray("home_screen"); JsonObject home = new JsonObject(); @@ -408,11 +406,8 @@ public class IAqualinkClient { class OneTouchDeserializer implements JsonDeserializer { @Override - public OneTouch[] deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - if (json == null) { - throw new JsonParseException("No JSON"); - } + public OneTouch @Nullable [] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonArray oneTouchScreen = jsonObject.getAsJsonArray("onetouch_screen"); List list = new ArrayList<>(); @@ -429,7 +424,7 @@ public class IAqualinkClient { oneTouchJson.add(oneTouchEntry.getKey(), oneTouchEntry.getValue()); }); }); - list.add(gsonInternal.fromJson(oneTouchJson, OneTouch.class)); + list.add(Objects.requireNonNull(gsonInternal.fromJson(oneTouchJson, OneTouch.class))); } } }); @@ -441,11 +436,8 @@ public class IAqualinkClient { class AuxDeserializer implements JsonDeserializer { @Override - public Auxiliary[] deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - if (json == null) { - throw new JsonParseException("No JSON"); - } + public Auxiliary @Nullable [] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonArray auxScreen = jsonObject.getAsJsonArray("devices_screen"); List list = new ArrayList<>(); @@ -462,7 +454,7 @@ public class IAqualinkClient { auxJson.add(auxEntry.getKey(), auxEntry.getValue()); }); }); - list.add(gsonInternal.fromJson(auxJson, Auxiliary.class)); + list.add(Objects.requireNonNull(gsonInternal.fromJson(auxJson, Auxiliary.class))); } } }); diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java index 03dd84d25c3..07628ad1f50 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java @@ -20,10 +20,7 @@ import java.net.SocketTimeoutException; import java.net.URI; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.*; import org.apache.commons.lang.StringUtils; @@ -238,6 +235,11 @@ public class InnogyBridgeHandler extends BaseBridgeHandler } Device bridgeDevice = deviceStructMan.getBridgeDevice(); + if (bridgeDevice == null) { + logger.debug("Failed to get bridge device, re-scheduling startClient."); + scheduleRestartClient(true); + return; + } setBridgeProperties(bridgeDevice); bridgeId = bridgeDevice.getId(); startWebsocket(); @@ -533,7 +535,7 @@ public class InnogyBridgeHandler extends BaseBridgeHandler case BaseEvent.TYPE_NEW_MESSAGE_RECEIVED: case BaseEvent.TYPE_MESSAGE_CREATED: final MessageEvent messageEvent = gson.fromJson(msg, MessageEvent.class); - handleNewMessageReceivedEvent(messageEvent); + handleNewMessageReceivedEvent(Objects.requireNonNull(messageEvent)); break; case BaseEvent.TYPE_MESSAGE_DELETED: diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/CommandHandler.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/CommandHandler.java index cb2e871aafb..b0c6f31d68a 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/CommandHandler.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/CommandHandler.java @@ -63,7 +63,7 @@ public abstract class CommandHandler { /** * Implements what to do when an openHAB command is received * - * @param config the configuration for the item that generated the command + * @param conf the configuration for the item that generated the command * @param cmd the openhab command issued * @param device the Insteon device to which this command applies */ diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceFeature.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceFeature.java index 76d3404254a..cb55463a35e 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceFeature.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceFeature.java @@ -16,11 +16,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -440,8 +436,7 @@ public class DeviceFeature { static { // read features from xml file and store them in a map InputStream input = DeviceFeature.class.getResourceAsStream("/device_features.xml"); - if (input != null) { - readFeatureTemplates(input); - } + Objects.requireNonNull(input); + readFeatureTemplates(input); } } diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java index 79b368dd210..a3845e6d2ea 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java @@ -74,7 +74,7 @@ public class DeviceTypeLoader { * Reads the device types from input stream and stores them in memory for * later access. * - * @param is the input stream from which to read + * @param in the input stream from which to read */ public void loadDeviceTypesXML(InputStream in) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -204,20 +204,18 @@ public class DeviceTypeLoader { public static synchronized DeviceTypeLoader instance() { if (deviceTypeLoader.getDeviceTypes().isEmpty()) { InputStream input = DeviceTypeLoader.class.getResourceAsStream("/device_types.xml"); - if (input != null) { - try { + try { + if (input != null) { deviceTypeLoader.loadDeviceTypesXML(input); - } catch (ParserConfigurationException e) { - logger.warn("parser config error when reading device types xml file: ", e); - } catch (SAXException e) { - logger.warn("SAX exception when reading device types xml file: ", e); - } catch (IOException e) { - logger.warn("I/O exception when reading device types xml file: ", e); + } else { + logger.warn("Resource stream is null, cannot read xml file."); } - logger.debug("loaded {} devices: ", deviceTypeLoader.getDeviceTypes().size()); - deviceTypeLoader.logDeviceTypes(); - } else { - logger.warn("unable to get device types xml file as a resource"); + } catch (ParserConfigurationException e) { + logger.warn("parser config error when reading device types xml file: ", e); + } catch (SAXException e) { + logger.warn("SAX exception when reading device types xml file: ", e); + } catch (IOException e) { + logger.warn("I/O exception when reading device types xml file: ", e); } } return deviceTypeLoader; diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonDeviceHandler.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonDeviceHandler.java index 736f86ec0c3..2e53e8a00b4 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonDeviceHandler.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonDeviceHandler.java @@ -14,13 +14,7 @@ package org.openhab.binding.insteon.internal.handler; import java.lang.reflect.Type; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -185,7 +179,7 @@ public class InsteonDeviceHandler extends BaseThingHandler { Type mapType = new TypeToken>() { }.getType(); try { - deviceConfigMap = new Gson().fromJson(deviceConfig, mapType); + deviceConfigMap = Objects.requireNonNull(new Gson().fromJson(deviceConfig, mapType)); } catch (JsonParseException e) { String msg = "The device configuration parameter is not valid JSON."; logger.warn("{} {}", thing.getUID().getAsString(), msg); diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java index 8d1f16a60c6..75baefa64f0 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java @@ -177,6 +177,8 @@ public class JablotronJa100Handler extends JablotronAlarmHandler { if (channel == null) { logger.debug("Creating a new temperature channel: {}", segmentId); createTempChannel(segmentId, segment.getSegmentName()); + processThermometer(segment); + return; } updateTemperatureChannel(channel, segment); } @@ -187,6 +189,8 @@ public class JablotronJa100Handler extends JablotronAlarmHandler { if (channel == null) { logger.debug("Creating a new thermostat channel: {}", segmentId); createThermostatChannel(segmentId, segment.getSegmentName()); + processThermostat(segment); + return; } updateTemperatureChannel(channel, segment); } diff --git a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/KM200Utils.java b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/KM200Utils.java index 06b4dceff51..5a49001a0a6 100644 --- a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/KM200Utils.java +++ b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/KM200Utils.java @@ -54,15 +54,21 @@ public class KM200Utils { */ public static String checkParameterReplacement(Channel channel, KM200Device device) { String service = KM200Utils.translatesNameToPath(channel.getProperties().get("root")); - if (service.contains(SWITCH_PROGRAM_REPLACEMENT)) { - String currentService = KM200Utils - .translatesNameToPath(channel.getProperties().get(SWITCH_PROGRAM_CURRENT_PATH_NAME)); + if (service == null) { + LOGGER.warn("Root property not found in device {}", device); + throw new IllegalStateException("root property not found"); + } + String currentService = KM200Utils + .translatesNameToPath(channel.getProperties().get(SWITCH_PROGRAM_CURRENT_PATH_NAME)); + if (currentService != null) { if (device.containsService(currentService)) { KM200ServiceObject curSerObj = device.getServiceObject(currentService); if (null != curSerObj) { if (DATA_TYPE_STRING_VALUE.equals(curSerObj.getServiceType())) { String val = (String) curSerObj.getValue(); - service = service.replace(SWITCH_PROGRAM_REPLACEMENT, val); + if (val != null) { + service = service.replace(SWITCH_PROGRAM_REPLACEMENT, val); + } return service; } } diff --git a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200SwitchProgramServiceHandler.java b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200SwitchProgramServiceHandler.java index 1262b315573..55c85806f1b 100644 --- a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200SwitchProgramServiceHandler.java +++ b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200SwitchProgramServiceHandler.java @@ -354,7 +354,7 @@ public class KM200SwitchProgramServiceHandler { firstVal = (BigDecimal) setpObject.serviceTreeMap.get(key).getValue(); } else { BigDecimal nextVal = (BigDecimal) setpObject.serviceTreeMap.get(key).getValue(); - if (null != nextVal) { + if (null != nextVal && null != firstVal) { if (nextVal.compareTo(firstVal) > 0) { positiveSwitch = key; } else { diff --git a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200ThingHandler.java b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200ThingHandler.java index 98b330aae9b..eb771ddab21 100644 --- a/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200ThingHandler.java +++ b/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/handler/KM200ThingHandler.java @@ -231,6 +231,10 @@ public class KM200ThingHandler extends BaseThingHandler { return; } String service = KM200Utils.translatesNameToPath(thing.getProperties().get("root")); + if (service == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "root property missing"); + return; + } synchronized (gateway.getDevice()) { updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.CONFIGURATION_PENDING); if (!gateway.getDevice().getInited()) { @@ -284,10 +288,14 @@ public class KM200ThingHandler extends BaseThingHandler { state = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO).withStep(BigDecimal.ONE) .withPattern("%d minutes").build(); String posName = thing.getProperties().get(SWITCH_PROGRAM_POSITIVE); - newChannel = createChannel(new ChannelTypeUID(thing.getUID().getAsString() + ":" + posName), - new ChannelUID(thing.getUID(), posName), service + "/" + posName, CoreItemFactory.NUMBER, - currentPathName, "Positive switch of the cycle, like 'Day' 'On'", posName, true, true, state, - "minutes"); + if (posName == null) { + newChannel = null; + } else { + newChannel = createChannel(new ChannelTypeUID(thing.getUID().getAsString() + ":" + posName), + new ChannelUID(thing.getUID(), posName), service + "/" + posName, CoreItemFactory.NUMBER, + currentPathName, "Positive switch of the cycle, like 'Day' 'On'", posName, true, true, + state, "minutes"); + } if (null == newChannel) { logger.warn("Creation of the channel {} was not possible", thing.getUID()); } else { @@ -295,10 +303,14 @@ public class KM200ThingHandler extends BaseThingHandler { } String negName = thing.getProperties().get(SWITCH_PROGRAM_NEGATIVE); - newChannel = createChannel(new ChannelTypeUID(thing.getUID().getAsString() + ":" + negName), - new ChannelUID(thing.getUID(), negName), service + "/" + negName, CoreItemFactory.NUMBER, - currentPathName, "Negative switch of the cycle, like 'Night' 'Off'", negName, true, true, state, - "minutes"); + if (negName == null) { + newChannel = null; + } else { + newChannel = createChannel(new ChannelTypeUID(thing.getUID().getAsString() + ":" + negName), + new ChannelUID(thing.getUID(), negName), service + "/" + negName, CoreItemFactory.NUMBER, + currentPathName, "Negative switch of the cycle, like 'Night' 'Off'", negName, true, true, + state, "minutes"); + } if (null == newChannel) { logger.warn("Creation of the channel {} was not possible", thing.getUID()); } else { diff --git a/bundles/org.openhab.binding.kvv/src/main/java/org/openhab/binding/kvv/internal/KVVBridgeHandler.java b/bundles/org.openhab.binding.kvv/src/main/java/org/openhab/binding/kvv/internal/KVVBridgeHandler.java index 0d9d6724a4f..aea4a38554a 100644 --- a/bundles/org.openhab.binding.kvv/src/main/java/org/openhab/binding/kvv/internal/KVVBridgeHandler.java +++ b/bundles/org.openhab.binding.kvv/src/main/java/org/openhab/binding/kvv/internal/KVVBridgeHandler.java @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; /** * KVVBridgeHandler encapsulates the communication with the KVV API. @@ -106,7 +107,7 @@ public class KVVBridgeHandler extends BaseBridgeHandler { DepartureResult result; try { result = new Gson().fromJson(data, DepartureResult.class); - } catch (Exception e) { + } catch (JsonSyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to connect to KVV API"); logger.debug("Failed to parse departure data", e); logger.debug("Server returned '{}'", data); @@ -114,6 +115,10 @@ public class KVVBridgeHandler extends BaseBridgeHandler { return null; } + if (result == null) { + return null; + } + if (this.wasOffline) { updateStatus(ThingStatus.ONLINE); } @@ -132,7 +137,6 @@ public class KVVBridgeHandler extends BaseBridgeHandler { /** * Creates a new @{link Cache}. * - * @param updateInterval the @{code updateInterval} */ public Cache() { this.updateInterval = KVVBindingConstants.CACHE_DEFAULT_UPDATEINTERVAL; diff --git a/bundles/org.openhab.binding.lametrictime/src/3rdparty/java/org/openhab/binding/lametrictime/api/common/impl/typeadapters/imported/CustomizedTypeAdapterFactory.java b/bundles/org.openhab.binding.lametrictime/src/3rdparty/java/org/openhab/binding/lametrictime/api/common/impl/typeadapters/imported/CustomizedTypeAdapterFactory.java index 4bfdc9494cf..2162ceab840 100644 --- a/bundles/org.openhab.binding.lametrictime/src/3rdparty/java/org/openhab/binding/lametrictime/api/common/impl/typeadapters/imported/CustomizedTypeAdapterFactory.java +++ b/bundles/org.openhab.binding.lametrictime/src/3rdparty/java/org/openhab/binding/lametrictime/api/common/impl/typeadapters/imported/CustomizedTypeAdapterFactory.java @@ -5,6 +5,7 @@ package org.openhab.binding.lametrictime.api.common.impl.typeadapters.imported; import java.io.IOException; +import java.io.ObjectStreamException; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -51,6 +52,9 @@ public abstract class CustomizedTypeAdapterFactory implements TypeAdapterFact { JsonElement tree = elementAdapter.read(in); afterRead(tree); + if (tree == null) { + throw new IOException("null reader"); + } return delegate.fromJsonTree(tree); } }; diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/Connection.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/Connection.java index f89a7051c1e..6ab835553cf 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/Connection.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/Connection.java @@ -21,12 +21,7 @@ import java.nio.channels.Channel; import java.nio.channels.CompletionHandler; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Queue; +import java.util.*; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; @@ -150,7 +145,7 @@ public class Connection { * @return the data */ public ModInfo updateModuleData(LcnAddrMod addr) { - return modData.computeIfAbsent(addr, ModInfo::new); + return Objects.requireNonNull(modData.computeIfAbsent(addr, ModInfo::new)); } /** diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/ConnectionStateConnecting.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/ConnectionStateConnecting.java index 35f54d8b227..b5057b93682 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/ConnectionStateConnecting.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/ConnectionStateConnecting.java @@ -17,6 +17,7 @@ import java.net.InetSocketAddress; import java.net.StandardSocketOptions; import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.CompletionHandler; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -78,15 +79,13 @@ public class ConnectionStateConnecting extends AbstractConnectionState { } private void handleConnectionFailure(@Nullable Throwable e) { - String message; + String message = null; if (e != null) { logger.warn("Could not connect to {}:{}: {}", connection.getSettings().getAddress(), connection.getSettings().getPort(), e.getMessage()); message = e.getMessage(); - } else { - message = ""; } - connection.getCallback().onOffline(message); + connection.getCallback().onOffline(Objects.requireNonNullElse(message, "")); context.handleConnectionFailed(e); } diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java index 4dbc86d69e0..2f0389b09ce 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java @@ -36,6 +36,7 @@ package org.openhab.binding.lgwebos.internal.handler.command; import java.util.function.Function; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener; import com.google.gson.JsonElement; @@ -57,11 +58,11 @@ public class ServiceCommand { protected Type type; protected JsonObject payload; protected String target; - protected Function converter; + protected Function converter; ResponseListener responseListener; - public ServiceCommand(String targetURL, JsonObject payload, Function converter, + public ServiceCommand(String targetURL, JsonObject payload, Function converter, ResponseListener listener) { this.target = targetURL; this.payload = payload; diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java index 02f697f37f8..8da6d0edc67 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java @@ -35,6 +35,7 @@ package org.openhab.binding.lgwebos.internal.handler.command; import java.util.function.Function; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener; import com.google.gson.JsonObject; @@ -48,7 +49,7 @@ import com.google.gson.JsonObject; */ public class ServiceSubscription extends ServiceCommand { - public ServiceSubscription(String uri, JsonObject payload, Function converter, + public ServiceSubscription(String uri, JsonObject payload, Function converter, ResponseListener listener) { super(uri, payload, converter, listener); type = Type.subscribe; diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/handler/LifxLightHandler.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/handler/LifxLightHandler.java index d14e1ee84e9..6c59b8fa0b5 100644 --- a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/handler/LifxLightHandler.java +++ b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/handler/LifxLightHandler.java @@ -636,6 +636,7 @@ public class LifxLightHandler extends BaseThingHandler { .setTemperature(percentTypeToKelvin(localPowerOnTemperature, product.getTemperatureRange())); } + PercentType powerOnBrightness = this.powerOnBrightness; if (powerOnBrightness != null) { PercentType newBrightness = onOff == OnOffType.ON ? powerOnBrightness : new PercentType(0); getLightStateForCommand().setBrightness(newBrightness); diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java index d44ece03d49..67aabcd0289 100644 --- a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java +++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java @@ -213,7 +213,7 @@ public class EnedisHttpApi { public UserInfo getUserInfo() throws LinkyException { final String user_info_url = URL_APPS_LINCS + "/userinfos"; String data = getData(user_info_url); - return gson.fromJson(data, UserInfo.class); + return Objects.requireNonNull(gson.fromJson(data, UserInfo.class)); } private Consumption getMeasures(String userId, String prmId, LocalDate from, LocalDate to, String request) diff --git a/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java b/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java index 4a0ea241ff2..59e0a520d0c 100644 --- a/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java +++ b/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java @@ -533,14 +533,14 @@ public class LxServerHandler extends BaseThingHandler implements LxServerHandler channels.sort((c1, c2) -> { String label1 = c1.getLabel(); String label2 = c2.getLabel(); - if (label1 == null && label2 != null) { + if (label1 != null && label2 != null) { + return label1.compareTo(label2); + } else if (label1 == null && label2 != null) { return 1; } else if (label1 != null && label2 == null) { return -1; - } else if (label1 == null && label2 == null) { - return 0; } else { - return label1.compareTo(label2); + return 0; } }); ThingBuilder builder = editThing(); diff --git a/bundles/org.openhab.binding.luftdateninfo/src/main/java/org/openhab/binding/luftdateninfo/internal/handler/HTTPHandler.java b/bundles/org.openhab.binding.luftdateninfo/src/main/java/org/openhab/binding/luftdateninfo/internal/handler/HTTPHandler.java index c65e4276bf0..5aa3d48b58e 100644 --- a/bundles/org.openhab.binding.luftdateninfo/src/main/java/org/openhab/binding/luftdateninfo/internal/handler/HTTPHandler.java +++ b/bundles/org.openhab.binding.luftdateninfo/src/main/java/org/openhab/binding/luftdateninfo/internal/handler/HTTPHandler.java @@ -14,6 +14,7 @@ package org.openhab.binding.luftdateninfo.internal.handler; import java.time.LocalDateTime; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -82,7 +83,7 @@ public class HTTPHandler { } else { failure = result.getFailure().getMessage(); } - callback.onError(failure); + callback.onError(Objects.requireNonNullElse(failure, "Unknown error")); } else { callback.onResponse(getContentAsString()); } diff --git a/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerEvalTest.java b/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerEvalTest.java index 53d70691a45..2d9d605c487 100644 --- a/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerEvalTest.java +++ b/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerEvalTest.java @@ -15,6 +15,7 @@ package org.openhab.binding.luftdateninfo.internal; import static org.junit.jupiter.api.Assertions.*; import java.util.List; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -41,14 +42,17 @@ public class HTTPHandlerEvalTest { public void setUp() { String conditionsStr = FileReader.readFileInString("src/test/resources/condition-result-no-pressure.json"); assertNotNull(conditionsStr); + Objects.requireNonNull(conditionsStr); conditions = http.getLatestValues(conditionsStr); String particulateStr = FileReader.readFileInString("src/test/resources/pm-result.json"); assertNotNull(particulateStr); + Objects.requireNonNull(particulateStr); particulate = http.getLatestValues(particulateStr); String noiseStr = FileReader.readFileInString("src/test/resources/noise-result.json"); assertNotNull(noiseStr); + Objects.requireNonNull(noiseStr); noise = http.getLatestValues(noiseStr); } diff --git a/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerValueTest.java b/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerValueTest.java index 1ea6da25809..3e8936c817c 100644 --- a/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerValueTest.java +++ b/bundles/org.openhab.binding.luftdateninfo/src/test/java/org/openhab/binding/luftdateninfo/internal/HTTPHandlerValueTest.java @@ -15,6 +15,7 @@ package org.openhab.binding.luftdateninfo.internal; import static org.junit.jupiter.api.Assertions.*; import java.util.List; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; @@ -39,8 +40,10 @@ public class HTTPHandlerValueTest { public void testValueDecoding() { String resource1 = FileReader.readFileInString("src/test/resources/condition-result-no-pressure.json"); assertNotNull(resource1); + Objects.requireNonNull(resource1); List l = http.getLatestValues(resource1); assertNotNull(l); + Objects.requireNonNull(l); l.forEach(sd -> { testSensorValue(sd); }); @@ -48,8 +51,10 @@ public class HTTPHandlerValueTest { String resource2 = FileReader .readFileInString("src/test/resources/condition-result-no-pressure-flipped-values.json"); assertNotNull(resource2); + Objects.requireNonNull(resource2); l = http.getLatestValues(resource2); assertNotNull(l); + Objects.requireNonNull(l); l.forEach(sd -> { testSensorValue(sd); }); diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/discovery/LeapDeviceDiscoveryService.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/discovery/LeapDeviceDiscoveryService.java index 45db7dc0834..af84f6195d8 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/discovery/LeapDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/discovery/LeapDeviceDiscoveryService.java @@ -150,9 +150,11 @@ public class LeapDeviceDiscoveryService extends AbstractDiscoveryService } else { areaName = "Occupancy Group"; } - logger.debug("Discovered occupancy group: {} areas: {} area name: {}", groupNum, - oGroup.associatedAreas.length, areaName); - notifyDiscovery(THING_TYPE_OGROUP, groupNum, areaName); + if (areaName != null) { + logger.debug("Discovered occupancy group: {} areas: {} area name: {}", groupNum, + oGroup.associatedAreas.length, areaName); + notifyDiscovery(THING_TYPE_OGROUP, groupNum, areaName); + } } } this.areaMap = null; diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/protocol/leap/LeapMessageParser.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/protocol/leap/LeapMessageParser.java index a8d96050a1c..47867a34847 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/protocol/leap/LeapMessageParser.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/protocol/leap/LeapMessageParser.java @@ -14,6 +14,7 @@ package org.openhab.binding.lutron.internal.protocol.leap; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -212,6 +213,7 @@ public class LeapMessageParser { try { if (messageBody.has(memberName)) { JsonObject jsonObject = messageBody.get(memberName).getAsJsonObject(); + @Nullable T obj = gson.fromJson(jsonObject, type); return obj; } else { @@ -233,7 +235,7 @@ public class LeapMessageParser { for (JsonElement element : jsonArray) { JsonObject jsonObject = element.getAsJsonObject(); - T obj = gson.fromJson(jsonObject, type); + T obj = Objects.requireNonNull(gson.fromJson(jsonObject, type)); objList.add(obj); } return objList; diff --git a/bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVControl.java b/bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVControl.java index bc218d9d71a..df901d91f38 100644 --- a/bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVControl.java +++ b/bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVControl.java @@ -391,10 +391,7 @@ public class MagentaTVControl { // direct key code return key; } - if (KEY_MAP.containsKey(key)) { - return KEY_MAP.get(key); - } - return ""; + return KEY_MAP.getOrDefault(key, ""); } /** diff --git a/bundles/org.openhab.binding.meteoalerte/src/main/java/org/openhab/binding/meteoalerte/internal/handler/MeteoAlerteHandler.java b/bundles/org.openhab.binding.meteoalerte/src/main/java/org/openhab/binding/meteoalerte/internal/handler/MeteoAlerteHandler.java index 7dfcc29952c..371c2402359 100644 --- a/bundles/org.openhab.binding.meteoalerte/src/main/java/org/openhab/binding/meteoalerte/internal/handler/MeteoAlerteHandler.java +++ b/bundles/org.openhab.binding.meteoalerte/src/main/java/org/openhab/binding/meteoalerte/internal/handler/MeteoAlerteHandler.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.AbstractMap; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -115,9 +116,13 @@ public class MeteoAlerteHandler extends BaseThingHandler { throw new MalformedURLException("queryUrl not initialized"); } String response = HttpUtil.executeUrl("GET", queryUrl, TIMEOUT_MS); + if (response == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "empty response"); + return; + } updateStatus(ThingStatus.ONLINE); ApiResponse apiResponse = gson.fromJson(response, ApiResponse.class); - updateChannels(apiResponse); + updateChannels(Objects.requireNonNull(apiResponse)); } catch (MalformedURLException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, String.format("Querying '%s' raised : %s", queryUrl, e.getMessage())); diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java index 63f1929da7f..92df54e41ad 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java @@ -129,9 +129,9 @@ public class MiIoBasicHandler extends MiIoAbstractHandler { } logger.debug("Locating action for {} channel '{}': '{}'", getThing().getUID(), channelUID.getId(), command); if (!actions.isEmpty()) { - if (actions.containsKey(channelUID)) { + MiIoBasicChannel miIoBasicChannel = actions.get(channelUID); + if (miIoBasicChannel != null) { int valuePos = 0; - MiIoBasicChannel miIoBasicChannel = actions.get(channelUID); for (MiIoDeviceAction action : miIoBasicChannel.getActions()) { @Nullable JsonElement value = null; diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java index 1966d9bf7fb..fbda70afd5d 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java @@ -17,12 +17,7 @@ import static org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal import java.math.BigDecimal; import java.time.Duration; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.TimeUnit; import org.apache.commons.lang.NotImplementedException; @@ -922,7 +917,8 @@ public class ModbusDataThingHandler extends BaseThingHandler { } private ChannelUID getChannelUID(String channelID) { - return channelCache.computeIfAbsent(channelID, id -> new ChannelUID(getThing().getUID(), id)); + return Objects + .requireNonNull(channelCache.computeIfAbsent(channelID, id -> new ChannelUID(getThing().getUID(), id))); } private void updateStatusIfChanged(ThingStatus status) { diff --git a/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/mapping/MqttTopicClassMapperTests.java b/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/mapping/MqttTopicClassMapperTests.java index 73d1bdfaab6..bfc7500b60b 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/mapping/MqttTopicClassMapperTests.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/mapping/MqttTopicClassMapperTests.java @@ -24,6 +24,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Field; import java.math.BigDecimal; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledExecutorService; import java.util.stream.Stream; @@ -201,8 +202,10 @@ public class MqttTopicClassMapperTests { String suffix = mapToField != null ? mapToField.suffix() : ""; assertThat(f.field.get(attributes).toString(), is(prefix + annotation.value() + suffix)); } else { - assertThat(Stream.of((String[]) f.field.get(attributes)).reduce((v, i) -> v + "," + i).orElse(""), - is(annotation.value())); + String[] attributeArray = (String[]) f.field.get(attributes); + assertNotNull(attributeArray); + Objects.requireNonNull(attributeArray); + assertThat(Stream.of(attributeArray).reduce((v, i) -> v + "," + i).orElse(""), is(annotation.value())); } } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/BaseChannelConfiguration.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/BaseChannelConfiguration.java index f0635264789..00db2dc330a 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/BaseChannelConfiguration.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/BaseChannelConfiguration.java @@ -14,6 +14,7 @@ package org.openhab.binding.mqtt.homeassistant.internal; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -54,7 +55,7 @@ public abstract class BaseChannelConfiguration { */ public static C fromString(final String configJSON, final Gson gson, final Class clazz) { - return gson.fromJson(configJSON, clazz); + return Objects.requireNonNull(gson.fromJson(configJSON, clazz)); } /** diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ChannelConfigurationTypeAdapterFactory.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ChannelConfigurationTypeAdapterFactory.java index 52f0e398b25..b07ace908a0 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ChannelConfigurationTypeAdapterFactory.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ChannelConfigurationTypeAdapterFactory.java @@ -69,10 +69,7 @@ public class ChannelConfigurationTypeAdapterFactory implements TypeAdapterFactor return new TypeAdapter() { @Override - public T read(@Nullable JsonReader in) throws IOException { - if (in == null) { - return null; - } + public @Nullable T read(JsonReader in) throws IOException { /* read the object using the default adapter, but translate the names in the reader */ T result = delegate.read(MappingJsonReader.getConfigMapper(in)); /* do the '~' expansion afterwards */ @@ -81,7 +78,7 @@ public class ChannelConfigurationTypeAdapterFactory implements TypeAdapterFactor } @Override - public void write(@Nullable JsonWriter out, T value) throws IOException { + public void write(JsonWriter out, @Nullable T value) throws IOException { delegate.write(out, value); } }; @@ -93,17 +90,14 @@ public class ChannelConfigurationTypeAdapterFactory implements TypeAdapterFactor return new TypeAdapter() { @Override - public T read(@Nullable JsonReader in) throws IOException { - if (in == null) { - return null; - } + public @Nullable T read(JsonReader in) throws IOException { /* read the object using the default adapter, but translate the names in the reader */ T result = delegate.read(MappingJsonReader.getDeviceMapper(in)); return result; } @Override - public void write(@Nullable JsonWriter out, T value) throws IOException { + public void write(JsonWriter out, @Nullable T value) throws IOException { delegate.write(out, value); } }; diff --git a/bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafControllerHandler.java b/bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafControllerHandler.java index 27742b152c0..ddfdb9a14f1 100644 --- a/bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafControllerHandler.java +++ b/bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafControllerHandler.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Scanner; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; @@ -493,9 +494,8 @@ public class NanoleafControllerHandler extends BaseBridgeHandler { if (line.startsWith("data:")) { String json = line.substring(5).trim(); // supposed to be JSON try { - @Nullable TouchEvents touchEvents = gson.fromJson(json, TouchEvents.class); - handleTouchEvents(touchEvents); + handleTouchEvents(Objects.requireNonNull(touchEvents)); } catch (JsonSyntaxException jse) { logger.error("couldn't parse touch event json {}", json); } @@ -645,9 +645,8 @@ public class NanoleafControllerHandler extends BaseBridgeHandler { private ControllerInfo receiveControllerInfo() throws NanoleafException, NanoleafUnauthorizedException { ContentResponse controllerlInfoJSON = OpenAPIUtils.sendOpenAPIRequest(OpenAPIUtils.requestBuilder(httpClient, getControllerConfig(), API_GET_CONTROLLER_INFO, HttpMethod.GET)); - @Nullable ControllerInfo controllerInfo = gson.fromJson(controllerlInfoJSON.getContentAsString(), ControllerInfo.class); - return controllerInfo; + return Objects.requireNonNull(controllerInfo); } private void sendStateCommand(String channel, Command command) throws NanoleafException { diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainApi.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainApi.java index 099ec5adeed..cdc2984f9b3 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainApi.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainApi.java @@ -76,7 +76,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), NeeoBrain.class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), NeeoBrain.class)); } /** @@ -97,7 +97,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), NeeoRoom.class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), NeeoRoom.class)); } /** @@ -121,7 +121,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), ExecuteResult.class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), ExecuteResult.class)); } /** @@ -145,7 +145,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), ExecuteResult.class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), ExecuteResult.class)); } /** @@ -163,7 +163,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), String[].class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), String[].class)); } /** @@ -189,7 +189,7 @@ public class NeeoBrainApi implements AutoCloseable { throw resp.createException(); } - return gson.fromJson(resp.getContent(), ExecuteResult.class); + return Objects.requireNonNull(gson.fromJson(resp.getContent(), ExecuteResult.class)); } /** diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java index 90ec7e88172..462f9f45b39 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java @@ -190,7 +190,7 @@ public class NeeoBrainHandler extends BaseBridgeHandler { public void post(String json) { triggerChannel(NeeoConstants.CHANNEL_BRAIN_FOWARDACTIONS, json); - final NeeoAction action = gson.fromJson(json, NeeoAction.class); + final NeeoAction action = Objects.requireNonNull(gson.fromJson(json, NeeoAction.class)); for (final Thing child : getThing().getThings()) { final ThingHandler th = child.getHandler(); diff --git a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeohubBoolDeserializer.java b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeohubBoolDeserializer.java index d83a337190c..1cca3ec41ea 100644 --- a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeohubBoolDeserializer.java +++ b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeohubBoolDeserializer.java @@ -35,16 +35,15 @@ import com.google.gson.JsonPrimitive; public class NeohubBoolDeserializer implements JsonDeserializer { @Override - public NeohubBool deserialize(@Nullable JsonElement json, @Nullable Type typeOfT, - @Nullable JsonDeserializationContext context) throws JsonParseException { - if (json != null) { - JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(); - if (jsonPrimitive.isBoolean()) { - return new NeohubBool(jsonPrimitive.getAsBoolean()); - } else if (jsonPrimitive.isNumber()) { - return new NeohubBool(jsonPrimitive.getAsNumber().intValue() != 0); - } + public @Nullable NeohubBool deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(); + if (jsonPrimitive.isBoolean()) { + return new NeohubBool(jsonPrimitive.getAsBoolean()); + } else if (jsonPrimitive.isNumber()) { + return new NeohubBool(jsonPrimitive.getAsNumber().intValue() != 0); } + return new NeohubBool(false); } } diff --git a/bundles/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/update/NestUpdateHandler.java b/bundles/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/update/NestUpdateHandler.java index 6da8ea92da9..dd51659310c 100644 --- a/bundles/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/update/NestUpdateHandler.java +++ b/bundles/org.openhab.binding.nest/src/main/java/org/openhab/binding/nest/internal/update/NestUpdateHandler.java @@ -60,11 +60,13 @@ public class NestUpdateHandler { private Set> getListeners(String nestId) { Set> listeners = new HashSet<>(); - if (listenersMap.get(nestId) != null) { - listeners.addAll(listenersMap.get(nestId)); + Set> idListeners = listenersMap.get(nestId); + if (idListeners != null) { + listeners.addAll(idListeners); } - if (listenersMap.get(ANY_ID) != null) { - listeners.addAll(listenersMap.get(ANY_ID)); + Set> anyListeners = listenersMap.get(ANY_ID); + if (anyListeners != null) { + listeners.addAll(anyListeners); } return listeners; } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/webhook/WelcomeWebHookServlet.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/webhook/WelcomeWebHookServlet.java index 8929af01255..e7fd8979331 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/webhook/WelcomeWebHookServlet.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/webhook/WelcomeWebHookServlet.java @@ -13,6 +13,7 @@ package org.openhab.binding.netatmo.internal.webhook; import java.io.IOException; +import java.util.Objects; import java.util.Scanner; import javax.servlet.ServletException; @@ -91,7 +92,7 @@ public class WelcomeWebHookServlet extends HttpServlet { if (!data.isEmpty() && handler != null) { NAWebhookCameraEvent event = gson.fromJson(data, NAWebhookCameraEvent.class); logger.debug("Event transmitted from restService"); - handler.webHookEvent(event); + handler.webHookEvent(Objects.requireNonNull(event)); } setHeaders(resp); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java index c0b369f1855..60c5a8409da 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java @@ -328,6 +328,10 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication for (Map location : data) { String id = location.get("id"); String name = location.get("name"); + if (id == null || name == null) { + logger.debug("id or name null, ignoring entry"); + continue; + } NhcLocation1 nhcLocation1 = new NhcLocation1(name); locations.put(id, nhcLocation1); } @@ -337,8 +341,11 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication logger.debug("Niko Home Control: list actions"); for (Map action : data) { - String id = action.get("id"); + if (id == null) { + logger.debug("id not found in action {}", action); + continue; + } String value1 = action.get("value1"); int state = ((value1 == null) || value1.isEmpty() ? 0 : Integer.parseInt(value1)); String value2 = action.get("value2"); @@ -349,6 +356,10 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication if (!actions.containsKey(id)) { // Initial instantiation of NhcAction class for action object String name = action.get("name"); + if (name == null) { + logger.debug("name not found in action {}", action); + continue; + } String type = action.get("type"); ActionType actionType = ActionType.GENERIC; switch (type) { @@ -371,8 +382,8 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication } String locationId = action.get("location"); String location = ""; - if (!locationId.isEmpty()) { - location = locations.get(locationId).getName(); + if (locationId != null && !locationId.isEmpty()) { + location = locations.getOrDefault(locationId, new NhcLocation1("")).getName(); } NhcAction nhcAction = new NhcAction1(id, name, actionType, location, this, scheduler); if (actionType == ActionType.ROLLERSHUTTER) { @@ -405,6 +416,10 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication for (Map thermostat : data) { try { String id = thermostat.get("id"); + if (id == null) { + logger.debug("skipping thermostat {}, id not found", thermostat); + continue; + } int measured = parseIntOrThrow(thermostat.get("measured")); int setpoint = parseIntOrThrow(thermostat.get("setpoint")); int mode = parseIntOrThrow(thermostat.get("mode")); @@ -528,6 +543,10 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication private void eventGetAlarms(Map data) { String alarmText = data.get("text"); + if (alarmText == null) { + logger.debug("message does not contain alarmtext: {}", data); + return; + } switch (data.getOrDefault("type", "")) { case "0": logger.debug("Niko Home Control: alarm - {}", alarmText); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java index b3e195b3d58..21c6de463fe 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java @@ -33,8 +33,7 @@ import java.util.stream.IntStream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.nikohomecontrol.internal.protocol.NhcControllerEvent; -import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication; +import org.openhab.binding.nikohomecontrol.internal.protocol.*; import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.ActionType; import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcDevice2.NhcProperty; import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcMessage2.NhcMessageParam; @@ -309,7 +308,7 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication return; } else if ("devices.added".equals(method)) { deviceList.forEach(this::addDevice); - } else if ("devices.changed".contentEquals(method)) { + } else if ("devices.changed".equals(method)) { deviceList.forEach(this::removeDevice); deviceList.forEach(this::addDevice); } @@ -444,12 +443,16 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication return; } - if (actions.containsKey(device.uuid)) { - updateActionState((NhcAction2) actions.get(device.uuid), deviceProperties); - } else if (thermostats.containsKey(device.uuid)) { - updateThermostatState((NhcThermostat2) thermostats.get(device.uuid), deviceProperties); - } else if (energyMeters.containsKey(device.uuid)) { - updateEnergyMeterState((NhcEnergyMeter2) energyMeters.get(device.uuid), deviceProperties); + NhcAction action = actions.get(device.uuid); + NhcThermostat thermostat = thermostats.get(device.uuid); + NhcEnergyMeter energyMeter = energyMeters.get(device.uuid); + + if (action != null) { + updateActionState((NhcAction2) action, deviceProperties); + } else if (thermostat != null) { + updateThermostatState((NhcThermostat2) thermostat, deviceProperties); + } else if (energyMeter != null) { + updateEnergyMeterState((NhcEnergyMeter2) energyMeter, deviceProperties); } } diff --git a/bundles/org.openhab.binding.ntp/src/main/java/org/openhab/binding/ntp/internal/handler/NtpHandler.java b/bundles/org.openhab.binding.ntp/src/main/java/org/openhab/binding/ntp/internal/handler/NtpHandler.java index 9a4b84db2d0..0a95d5ca310 100644 --- a/bundles/org.openhab.binding.ntp/src/main/java/org/openhab/binding/ntp/internal/handler/NtpHandler.java +++ b/bundles/org.openhab.binding.ntp/src/main/java/org/openhab/binding/ntp/internal/handler/NtpHandler.java @@ -22,6 +22,7 @@ import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.Objects; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -122,8 +123,7 @@ public class NtpHandler extends BaseThingHandler { logger.debug("{} using default timezone '{}', because configuration setting '{}' is null.", getThing().getUID(), timeZoneProvider.getTimeZone(), PROPERTY_TIMEZONE); } - ZoneId zoneId = timeZoneId != null ? timeZoneId : timeZoneProvider.getTimeZone(); - + ZoneId zoneId = Objects.requireNonNullElse(timeZoneId, timeZoneProvider.getTimeZone()); Channel stringChannel = getThing().getChannel(CHANNEL_STRING); if (stringChannel != null) { String dateTimeFormatString = stringChannel.getConfiguration() @@ -183,7 +183,7 @@ public class NtpHandler extends BaseThingHandler { refreshNtpCount--; } - ZoneId zoneId = timeZoneId != null ? timeZoneId : timeZoneProvider.getTimeZone(); + ZoneId zoneId = Objects.requireNonNullElse(timeZoneId, timeZoneProvider.getTimeZone()); ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(networkTimeInMillis), zoneId); updateState(CHANNEL_DATE_TIME, new DateTimeType(zoned)); dateTimeFormat.withZone(zoneId); @@ -208,7 +208,7 @@ public class NtpHandler extends BaseThingHandler { timeInfo.computeDetails(); long serverMillis = timeInfo.getReturnTime() + timeInfo.getOffset(); - ZoneId zoneId = timeZoneId != null ? timeZoneId : timeZoneProvider.getTimeZone(); + ZoneId zoneId = Objects.requireNonNullElse(timeZoneId, timeZoneProvider.getTimeZone()); ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(serverMillis), zoneId); logger.debug("{} Got time update from host '{}': {}.", getThing().getUID(), hostname, zoned.format(DATE_FORMATTER_WITH_TZ)); diff --git a/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/NukiHandlerFactory.java b/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/NukiHandlerFactory.java index bc5c26a3f32..281c1e194d0 100644 --- a/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/NukiHandlerFactory.java +++ b/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/NukiHandlerFactory.java @@ -12,8 +12,6 @@ */ package org.openhab.binding.nuki.internal; -import java.util.ArrayList; - import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; @@ -118,9 +116,7 @@ public class NukiHandlerFactory extends BaseThingHandlerFactory { logger.warn("Cannot find port of the http service."); return null; } - ArrayList parameters = new ArrayList<>(); - parameters.add(ipAddress + ":" + port); - String callbackUrl = String.format(NukiBindingConstants.CALLBACK_URL, parameters.toArray()); + String callbackUrl = String.format(NukiBindingConstants.CALLBACK_URL, ipAddress + ":" + port); logger.trace("callbackUrl[{}]", callbackUrl); return callbackUrl; } diff --git a/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/dataexchange/NukiHttpClient.java b/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/dataexchange/NukiHttpClient.java index 8b62845c7bf..2279f087cc1 100644 --- a/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/dataexchange/NukiHttpClient.java +++ b/bundles/org.openhab.binding.nuki/src/main/java/org/openhab/binding/nuki/internal/dataexchange/NukiHttpClient.java @@ -17,7 +17,6 @@ import java.math.BigDecimal; import java.net.SocketException; import java.net.URLEncoder; import java.time.Instant; -import java.util.ArrayList; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -64,16 +63,12 @@ public class NukiHttpClient { String configIp = (String) configuration.get(NukiBindingConstants.CONFIG_IP); BigDecimal configPort = (BigDecimal) configuration.get(NukiBindingConstants.CONFIG_PORT); String configApiToken = (String) configuration.get(NukiBindingConstants.CONFIG_API_TOKEN); - ArrayList parameters = new ArrayList<>(); - parameters.add(configIp); - parameters.add(configPort.toString()); - parameters.add(configApiToken); - if (additionalArguments != null) { - for (String argument : additionalArguments) { - parameters.add(argument); - } - } - String uri = String.format(uriTemplate, parameters.toArray()); + String[] parameters = new String[additionalArguments.length + 3]; + parameters[0] = configIp; + parameters[1] = configPort.toString(); + parameters[2] = configApiToken; + System.arraycopy(additionalArguments, 0, parameters, 3, additionalArguments.length); + String uri = String.format(uriTemplate, parameters); logger.trace("prepareUri(...):URI[{}]", uri); return uri; } diff --git a/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/StopHandler.java b/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/StopHandler.java index 39fbf3be96f..0550a61f022 100644 --- a/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/StopHandler.java +++ b/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/StopHandler.java @@ -119,17 +119,16 @@ public class StopHandler extends BaseBridgeHandler { if (listener == null) { throw new IllegalArgumentException("It makes no sense to register a null listener!"); } - boolean added = routeDataListeners.add(listener); - if (added) { - String routeId = listener.getRouteId(); - List copiedRouteData; - synchronized (routeData) { - copiedRouteData = new ArrayList<>(routeData.get(routeId)); - } - Collections.sort(copiedRouteData); - listener.onNewRouteData(routeDataLastUpdateMs, copiedRouteData); + routeDataListeners.add(listener); + String routeId = listener.getRouteId(); + List copiedRouteData; + synchronized (routeData) { + copiedRouteData = new ArrayList<>(routeData.getOrDefault(routeId, List.of())); } - return added; + Collections.sort(copiedRouteData); + listener.onNewRouteData(routeDataLastUpdateMs, copiedRouteData); + + return true; } /** @@ -212,7 +211,8 @@ public class StopHandler extends BaseBridgeHandler { routeData.put(d.routeId, Arrays.asList(d)); } for (String key : routeData.keySet()) { - List copy = new ArrayList<>(routeData.get(key)); + List copy = new ArrayList<>( + routeData.getOrDefault(key, List.of())); Collections.sort(copy); copiedRouteData.put(key, copy); } diff --git a/bundles/org.openhab.binding.onewire/src/main/java/org/openhab/binding/onewire/internal/handler/BAE091xSensorThingHandler.java b/bundles/org.openhab.binding.onewire/src/main/java/org/openhab/binding/onewire/internal/handler/BAE091xSensorThingHandler.java index be112770c60..45abf951c77 100644 --- a/bundles/org.openhab.binding.onewire/src/main/java/org/openhab/binding/onewire/internal/handler/BAE091xSensorThingHandler.java +++ b/bundles/org.openhab.binding.onewire/src/main/java/org/openhab/binding/onewire/internal/handler/BAE091xSensorThingHandler.java @@ -102,7 +102,7 @@ public class BAE091xSensorThingHandler extends OwBaseThingHandler { BAE091xHandlerConfiguration configuration = getConfig().as(BAE091xHandlerConfiguration.class); Set wantedChannel = new HashSet<>(); - wantedChannel.addAll(SENSOR_TYPE_CHANNEL_MAP.get(sensorType)); + wantedChannel.addAll(SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of())); // Pin1: switch (configuration.pin1) { diff --git a/bundles/org.openhab.binding.pixometer/src/main/java/org/openhab/binding/pixometer/handler/MeterHandler.java b/bundles/org.openhab.binding.pixometer/src/main/java/org/openhab/binding/pixometer/handler/MeterHandler.java index 49d8289faf3..831cc1a06a1 100644 --- a/bundles/org.openhab.binding.pixometer/src/main/java/org/openhab/binding/pixometer/handler/MeterHandler.java +++ b/bundles/org.openhab.binding.pixometer/src/main/java/org/openhab/binding/pixometer/handler/MeterHandler.java @@ -16,6 +16,7 @@ import static org.openhab.binding.pixometer.internal.PixometerBindingConstants.* import java.io.IOException; import java.time.Duration; +import java.util.Objects; import java.util.Properties; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -253,7 +254,7 @@ public class MeterHandler extends BaseThingHandler { ReadingInstance latestReading = gson.fromJson(new JsonParser().parse(urlResponse), ReadingInstance.class); - return new MeterState(latestReading); + return new MeterState(Objects.requireNonNull(latestReading)); } catch (IOException e) { logger.debug("Exception while refreshing cache for Meter {}: {}", getThing().getUID(), e.getMessage(), e); return null; diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/rest/RemoteopenhabRestClient.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/rest/RemoteopenhabRestClient.java index 1f7b04a2b0b..0dff1cb7c59 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/rest/RemoteopenhabRestClient.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/rest/RemoteopenhabRestClient.java @@ -18,6 +18,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; @@ -286,12 +287,12 @@ public class RemoteopenhabRestClient { break; case "ItemAddedEvent": itemName = extractItemNameFromTopic(event.topic, event.type, "added"); - item = jsonParser.fromJson(event.payload, Item.class); + item = Objects.requireNonNull(jsonParser.fromJson(event.payload, Item.class)); listeners.forEach(listener -> listener.onItemAdded(item)); break; case "ItemRemovedEvent": itemName = extractItemNameFromTopic(event.topic, event.type, "removed"); - item = jsonParser.fromJson(event.payload, Item.class); + item = Objects.requireNonNull(jsonParser.fromJson(event.payload, Item.class)); listeners.forEach(listener -> listener.onItemRemoved(item)); break; case "ItemUpdatedEvent": diff --git a/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/StatusService.java b/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/StatusService.java index ee2c5c0ad70..d66bdffa310 100644 --- a/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/StatusService.java +++ b/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/StatusService.java @@ -13,6 +13,7 @@ package org.openhab.binding.revogi.internal.api; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -69,7 +70,7 @@ public class StatusService { private StatusRawDTO deserializeString(String response) { String extractedJsonResponse = response.substring(response.lastIndexOf(VERSION_STRING) + 2); try { - return gson.fromJson(extractedJsonResponse, StatusRawDTO.class); + return Objects.requireNonNull(gson.fromJson(extractedJsonResponse, StatusRawDTO.class)); } catch (JsonSyntaxException e) { logger.warn("Could not parse string \"{}\" to StatusRaw", response, e); return new StatusRawDTO(503, 0, new StatusDTO(false, 503, null, null, null)); diff --git a/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/SwitchService.java b/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/SwitchService.java index 4d79cc2078a..0147d73e497 100644 --- a/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/SwitchService.java +++ b/bundles/org.openhab.binding.revogi/src/main/java/org/openhab/binding/revogi/internal/api/SwitchService.java @@ -13,6 +13,7 @@ package org.openhab.binding.revogi.internal.api; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -76,7 +77,7 @@ public class SwitchService { private SwitchResponseDTO deserializeString(String response) { String extractedJsonResponse = response.substring(response.lastIndexOf(VERSION_STRING) + 2); try { - return gson.fromJson(extractedJsonResponse, SwitchResponseDTO.class); + return Objects.requireNonNull(gson.fromJson(extractedJsonResponse, SwitchResponseDTO.class)); } catch (JsonSyntaxException e) { logger.warn("Could not parse string \"{}\" to SwitchResponse", response); return new SwitchResponseDTO(0, 503); diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/discovery/RFXComDeviceDiscoveryService.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/discovery/RFXComDeviceDiscoveryService.java index 0f5b0e48f0b..48f698218a0 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/discovery/RFXComDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/discovery/RFXComDeviceDiscoveryService.java @@ -70,6 +70,10 @@ public class RFXComDeviceDiscoveryService extends AbstractDiscoveryService imple String id = message.getDeviceId(); ThingTypeUID uid = RFXComBindingConstants.PACKET_TYPE_THING_TYPE_UID_MAP.get(message.getPacketType()); + if (uid == null) { + logger.debug("cannot find uid for message {}", message); + return; + } ThingUID thingUID = new ThingUID(uid, bridge, id.replace(ID_DELIMITER, "_")); if (!bridgeHandler.getConfiguration().disableDiscovery) { diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java index 7e53cd64a88..514354dc626 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java @@ -984,7 +984,7 @@ public abstract class RotelConnector { } else { for (RotelSource src : sourcesLabels.keySet()) { String label = sourcesLabels.get(src); - if (value.startsWith(label)) { + if (label != null && value.startsWith(label)) { if (source == null || sourcesLabels.get(source).length() < label.length()) { source = src; } diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java index fe6df3c4505..1e583824634 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java @@ -16,6 +16,7 @@ import java.io.InterruptedIOException; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Map; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -1145,11 +1146,10 @@ public class RotelSimuConnector extends RotelConnector { String label; if (considerFollowMain && source.getName().equals(RotelSource.CAT1_FOLLOW_MAIN.getName())) { label = "SOURCE"; - } else if (sourcesLabels.get(source) != null) { - label = sourcesLabels.get(source); } else { - label = source.getLabel(); + label = Objects.requireNonNullElse(sourcesLabels.get(source), source.getLabel()); } + return label; } } diff --git a/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/service/MainTVServerService.java b/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/service/MainTVServerService.java index 4508197923d..d8bd37559f1 100644 --- a/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/service/MainTVServerService.java +++ b/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/service/MainTVServerService.java @@ -231,10 +231,8 @@ public class MainTVServerService implements UpnpIOParticipant, SamsungTvService if (result.get("Result").equals("OK")) { String xml = result.get("SourceList"); - - Map list = parseSourceList(xml); - if (list != null) { - id = list.get(source); + if (xml != null) { + id = parseSourceList(xml).get(source); } } else { logger.warn("Source list query failed, result='{}'", result.get("Result")); diff --git a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/event/IntegraStateEvent.java b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/event/IntegraStateEvent.java index 963f2bd42b3..16086811850 100644 --- a/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/event/IntegraStateEvent.java +++ b/bundles/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/event/IntegraStateEvent.java @@ -15,6 +15,7 @@ package org.openhab.binding.satel.internal.event; import java.util.BitSet; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.satel.internal.types.StateType; @@ -71,10 +72,10 @@ public class IntegraStateEvent implements SatelEvent { if (stateType.getStartByte() == 0 && bitsCount == stateBits.size()) { return stateBits; } - return stateBitsMap.computeIfAbsent(stateType, k -> { + return Objects.requireNonNull(stateBitsMap.computeIfAbsent(stateType, k -> { int startBit = k.getStartByte() * 8; return stateBits.get(startBit, startBit + bitsCount); - }); + })); } /** diff --git a/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeApi.java b/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeApi.java index ca4b7060d9a..f6416b366cf 100644 --- a/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeApi.java +++ b/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeApi.java @@ -14,6 +14,7 @@ package org.openhab.binding.senechome.internal; import java.io.IOException; import java.net.MalformedURLException; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -78,7 +79,7 @@ public class SenecHomeApi { .content(new StringContentProvider(gson.toJson(new SenecHomeResponse()))).send(); if (response.getStatus() == HttpStatus.OK_200) { - return gson.fromJson(response.getContentAsString(), SenecHomeResponse.class); + return Objects.requireNonNull(gson.fromJson(response.getContentAsString(), SenecHomeResponse.class)); } else { logger.trace("Got unexpected response code {}", response.getStatus()); throw new IOException("Got unexpected response code " + response.getStatus()); diff --git a/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeHandler.java b/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeHandler.java index 393485c82aa..78902720e14 100644 --- a/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeHandler.java +++ b/bundles/org.openhab.binding.senechome/src/main/java/org/openhab/binding/senechome/internal/SenecHomeHandler.java @@ -131,35 +131,44 @@ public class SenecHomeHandler extends BaseThingHandler { Channel channelLimitationState = getThing() .getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_POWER_LIMITATION_STATE); - updatePowerLimitationStatus(channelLimitationState, - (100 - pvLimitation.intValue()) <= config.limitationTresholdValue, config.limitationDuration); + if (channelLimitationState != null) { + updatePowerLimitationStatus(channelLimitationState, + (100 - pvLimitation.intValue()) <= config.limitationTresholdValue, config.limitationDuration); + } Channel channelConsumption = getThing() .getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_POWER_CONSUMPTION); - updateState(channelConsumption.getUID(), - new QuantityType( - getSenecValue(response.energy.homePowerConsumption).setScale(2, RoundingMode.HALF_UP), - SmartHomeUnits.WATT)); + if (channelConsumption != null) { + updateState(channelConsumption.getUID(), + new QuantityType( + getSenecValue(response.energy.homePowerConsumption).setScale(2, RoundingMode.HALF_UP), + SmartHomeUnits.WATT)); + } Channel channelEnergyProduction = getThing() .getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_ENERGY_PRODUCTION); - updateState(channelEnergyProduction.getUID(), - new QuantityType( - getSenecValue(response.energy.inverterPowerGeneration).setScale(0, RoundingMode.HALF_UP), - SmartHomeUnits.WATT)); + if (channelEnergyProduction != null) { + updateState(channelEnergyProduction.getUID(), new QuantityType( + getSenecValue(response.energy.inverterPowerGeneration).setScale(0, RoundingMode.HALF_UP), + SmartHomeUnits.WATT)); + } Channel channelBatteryPower = getThing().getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_BATTERY_POWER); - updateState(channelBatteryPower.getUID(), - new QuantityType( - getSenecValue(response.energy.batteryPower).setScale(2, RoundingMode.HALF_UP), - SmartHomeUnits.WATT)); + if (channelBatteryPower != null) { + updateState(channelBatteryPower.getUID(), + new QuantityType( + getSenecValue(response.energy.batteryPower).setScale(2, RoundingMode.HALF_UP), + SmartHomeUnits.WATT)); + } Channel channelBatteryFuelCharge = getThing() .getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_BATTERY_FUEL_CHARGE); - updateState(channelBatteryFuelCharge.getUID(), - new QuantityType( - getSenecValue(response.energy.batteryFuelCharge).setScale(0, RoundingMode.HALF_UP), - SmartHomeUnits.PERCENT)); + if (channelBatteryFuelCharge != null) { + updateState(channelBatteryFuelCharge.getUID(), + new QuantityType( + getSenecValue(response.energy.batteryFuelCharge).setScale(0, RoundingMode.HALF_UP), + SmartHomeUnits.PERCENT)); + } Channel channelGridCurrentPhase1 = getThing() .getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_GRID_CURRENT_PH1); @@ -266,7 +275,9 @@ public class SenecHomeHandler extends BaseThingHandler { SmartHomeUnits.VOLT)); Channel channelBatteryState = getThing().getChannel(SenecHomeBindingConstants.CHANNEL_SENEC_BATTERY_STATE); - updateBatteryState(channelBatteryState, getSenecValue(response.energy.batteryState).intValue()); + if (channelBatteryState != null) { + updateBatteryState(channelBatteryState, getSenecValue(response.energy.batteryState).intValue()); + } updateGridPowerValues(getSenecValue(response.grid.currentGridValue)); diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java index 48b11eba6e4..3c58886028b 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java @@ -98,13 +98,14 @@ public class SensiboAccountHandler extends BaseBridgeHandler { gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new TypeAdapter() { @Override - public void write(final @NonNullByDefault({}) JsonWriter out, final ZonedDateTime value) - throws IOException { - out.value(value.toString()); + public void write(JsonWriter out, @Nullable ZonedDateTime value) throws IOException { + if (value != null) { + out.value(value.toString()); + } } @Override - public ZonedDateTime read(final @NonNullByDefault({}) JsonReader in) throws IOException { + public @Nullable ZonedDateTime read(final JsonReader in) throws IOException { return ZonedDateTime.parse(in.nextString()); } }).setLenient().setPrettyPrinting().create(); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java index d0d09d32d34..50271e06295 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java @@ -18,6 +18,7 @@ import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsDimmer; @@ -103,7 +104,7 @@ public class ShellyDeviceProfile { try { initFromThingType(thingType); settingsJson = json; - settings = gson.fromJson(json, ShellySettingsGlobal.class); + settings = Objects.requireNonNull(gson.fromJson(json, ShellySettingsGlobal.class)); } catch (IllegalArgumentException | JsonSyntaxException e) { throw new ShellyApiException( thingName + ": Unable to transform settings JSON " + e.toString() + ", json='" + json + "'", e); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java index 574f2938e6e..87356a5a1e0 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java @@ -17,10 +17,7 @@ import static org.openhab.binding.shelly.internal.coap.ShellyCoapJSonDTO.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import java.net.UnknownHostException; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; import org.eclipse.californium.core.CoapClient; import org.eclipse.californium.core.coap.CoAP.Code; @@ -389,6 +386,7 @@ public class ShellyCoapHandler implements ShellyCoapListener { continue; } CoIotDescrSen sen = sensorMap.get(s.id); + Objects.requireNonNull(sen); // find matching sensor definition from device description, use the Link ID as index sen = coiot.fixDescription(sen, blkMap); if (!blkMap.containsKey(sen.links)) { diff --git a/bundles/org.openhab.binding.siemensrds/src/main/java/org/openhab/binding/siemensrds/points/PointDeserializer.java b/bundles/org.openhab.binding.siemensrds/src/main/java/org/openhab/binding/siemensrds/points/PointDeserializer.java index 467a05682ae..17212c20baf 100644 --- a/bundles/org.openhab.binding.siemensrds/src/main/java/org/openhab/binding/siemensrds/points/PointDeserializer.java +++ b/bundles/org.openhab.binding.siemensrds/src/main/java/org/openhab/binding/siemensrds/points/PointDeserializer.java @@ -41,12 +41,8 @@ public class PointDeserializer implements JsonDeserializer { } @Override - public BasePoint deserialize(@Nullable JsonElement element, @Nullable Type guff, - @Nullable JsonDeserializationContext ctxt) throws JsonParseException { - if (element == null || ctxt == null) { - throw new JsonParseException("method called with null argument(s)"); - } - + public @Nullable BasePoint deserialize(JsonElement element, Type guff, JsonDeserializationContext ctxt) + throws JsonParseException { JsonObject obj = element.getAsJsonObject(); JsonElement value = obj.get("value"); if (value == null) { diff --git a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterHandler.java b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterHandler.java index 5925fbb4d5f..560ecce8b04 100644 --- a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterHandler.java +++ b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/SmartMeterHandler.java @@ -252,10 +252,12 @@ public class SmartMeterHandler extends BaseThingHandler { Channel channel = this.thing.getChannel(channelId.getId()); if (channel != null) { String obis = channel.getProperties().get(SmartMeterBindingConstants.CHANNEL_PROPERTY_OBIS); - MeterValue value = this.smlDevice.getMeterValue(obis); - if (value != null) { - State state = getStateForObisValue(value, channel); - updateState(channel.getUID(), state); + if (obis != null) { + MeterValue value = this.smlDevice.getMeterValue(obis); + if (value != null) { + State state = getStateForObisValue(value, channel); + updateState(channel.getUID(), state); + } } } } diff --git a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/conformity/Conformity.java b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/conformity/Conformity.java index 91c691d9bee..dcc67cfa710 100644 --- a/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/conformity/Conformity.java +++ b/bundles/org.openhab.binding.smartmeter/src/main/java/org/openhab/binding/smartmeter/internal/conformity/Conformity.java @@ -67,28 +67,30 @@ public enum Conformity { // Negate if this channel has the unit "Watt" and the negate bit is set. Read from all other // channels the state and check if there is a negate bit. String channelObis = channel.getProperties().get(SmartMeterBindingConstants.CHANNEL_PROPERTY_OBIS); - MeterValue value = device.getMeterValue(channelObis); - if (value != null && SmartHomeUnits.WATT.isCompatible(value.getUnit())) { - for (String obis : device.getObisCodes()) { - try { - MeterValue otherValue = device.getMeterValue(obis); - ObisCode obisCode = ObisCode.from(obis); - if (otherValue != null) { - if (obisCode.matches((byte) 0x60, (byte) 0x05, (byte) 0x05)) { - // we found status status obis 96.5.5 - if (NegateHandler.isNegateSet(otherValue.getValue(), 5)) { - return currentState.negate(); - } - } else if (obisCode.matches((byte) 0x01, (byte) 0x08, (byte) 0x00)) { - // check obis 1.8.0 for status if status has negate bit set. - String status = otherValue.getStatus(); - if (status != null && NegateHandler.isNegateSet(status, 5)) { - return currentState.negate(); + if (channelObis != null) { + MeterValue value = device.getMeterValue(channelObis); + if (value != null && SmartHomeUnits.WATT.isCompatible(value.getUnit())) { + for (String obis : device.getObisCodes()) { + try { + MeterValue otherValue = device.getMeterValue(obis); + ObisCode obisCode = ObisCode.from(obis); + if (otherValue != null) { + if (obisCode.matches((byte) 0x60, (byte) 0x05, (byte) 0x05)) { + // we found status status obis 96.5.5 + if (NegateHandler.isNegateSet(otherValue.getValue(), 5)) { + return currentState.negate(); + } + } else if (obisCode.matches((byte) 0x01, (byte) 0x08, (byte) 0x00)) { + // check obis 1.8.0 for status if status has negate bit set. + String status = otherValue.getStatus(); + if (status != null && NegateHandler.isNegateSet(status, 5)) { + return currentState.negate(); + } } } + } catch (Exception e) { + logger.warn("Failed to check negate status for obis {}", obis, e); } - } catch (Exception e) { - logger.warn("Failed to check negate status for obis {}", obis, e); } } } diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsHandlerFactory.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsHandlerFactory.java index 35273cd52d4..8d9fd7cf256 100644 --- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsHandlerFactory.java +++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsHandlerFactory.java @@ -64,8 +64,7 @@ public class SmartthingsHandlerFactory extends BaseThingHandlerFactory implement private @Nullable SmartthingsBridgeHandler bridgeHandler = null; private @Nullable ThingUID bridgeUID; private Gson gson; - private List thingHandlers = Collections - .synchronizedList(new ArrayList()); + private List thingHandlers = Collections.synchronizedList(new ArrayList<>()); private @NonNullByDefault({}) HttpClient httpClient; @@ -153,6 +152,9 @@ public class SmartthingsHandlerFactory extends BaseThingHandlerFactory implement String data = (String) event.getProperty("data"); SmartthingsStateData stateData = new SmartthingsStateData(); stateData = gson.fromJson(data, stateData.getClass()); + if (stateData == null) { + return; + } SmartthingsThingHandler handler = findHandler(stateData); if (handler != null) { handler.handleStateMessage(stateData); diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java index 6982bc98399..2259b075c42 100644 --- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java +++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java @@ -12,10 +12,7 @@ */ package org.openhab.binding.smartthings.internal.discovery; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -166,11 +163,11 @@ public class SmartthingsDiscoveryService extends AbstractDiscoveryService implem // The data returned from the Smartthings hub is a list of strings where each // element is the data for one device. That device string is another json object - List devices = new ArrayList(); + List devices = new ArrayList<>(); devices = gson.fromJson(data, devices.getClass()); for (String device : devices) { SmartthingsDeviceData deviceData = gson.fromJson(device, SmartthingsDeviceData.class); - createDevice(deviceData); + createDevice(Objects.requireNonNull(deviceData)); } } diff --git a/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandler.java b/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandler.java index 1a62361b4f8..040320c45e9 100644 --- a/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandler.java +++ b/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandler.java @@ -372,11 +372,13 @@ public class SmhiHandler extends BaseThingHandler { // See https://github.com/openhab/openhab-webui/issues/212 Set hours = new TreeSet<>(); Set days = new TreeSet<>(); - if (config.hourlyForecasts != null) { - hours.addAll(config.hourlyForecasts); + List hourlyForecasts = config.hourlyForecasts; + if (hourlyForecasts != null) { + hours.addAll(hourlyForecasts); } - if (config.dailyForecasts != null) { - days.addAll(config.dailyForecasts); + List dailyForecasts = config.dailyForecasts; + if (dailyForecasts != null) { + days.addAll(dailyForecasts); } for (int i : hours) { diff --git a/bundles/org.openhab.binding.somfymylink/src/main/java/org/openhab/binding/somfymylink/internal/handler/SomfyMyLinkBridgeHandler.java b/bundles/org.openhab.binding.somfymylink/src/main/java/org/openhab/binding/somfymylink/internal/handler/SomfyMyLinkBridgeHandler.java index 94e045870b7..dc208a12431 100644 --- a/bundles/org.openhab.binding.somfymylink/src/main/java/org/openhab/binding/somfymylink/internal/handler/SomfyMyLinkBridgeHandler.java +++ b/bundles/org.openhab.binding.somfymylink/src/main/java/org/openhab/binding/somfymylink/internal/handler/SomfyMyLinkBridgeHandler.java @@ -23,10 +23,7 @@ import java.io.Writer; import java.net.Socket; import java.net.SocketTimeoutException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -351,7 +348,7 @@ public class SomfyMyLinkBridgeHandler extends BaseBridgeHandler { throw new SomfyMyLinkException("Incomplete message."); } - return gson.fromJson(jsonObj, responseType); + return Objects.requireNonNull(gson.fromJson(jsonObj, responseType)); } private Socket getConnection() throws IOException, SomfyMyLinkException { diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java index 1f12dc80951..7e12dc9cd63 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java @@ -130,8 +130,9 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler { protected void refresh(String channel) { SomfyTahomaBridgeHandler handler = getBridgeHandler(); - if (handler != null && stateNames.containsKey(channel)) { - handler.refresh(url, stateNames.get(channel)); + String stateName = stateNames.get(channel); + if (handler != null && stateName != null) { + handler.refresh(url, stateName); } } diff --git a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/SpotifyApi.java b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/SpotifyApi.java index afda601eaf6..628c2cb1f02 100644 --- a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/SpotifyApi.java +++ b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/SpotifyApi.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Function; import java.util.stream.Collectors; @@ -88,7 +89,7 @@ public class SpotifyApi { public Me getMe() { final ContentResponse response = request(GET, SPOTIFY_API_URL, ""); - return ModelUtil.gsonInstance().fromJson(response.getContentAsString(), Me.class); + return Objects.requireNonNull(ModelUtil.gsonInstance().fromJson(response.getContentAsString(), Me.class)); } /** diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/ZoneSettingsBuilder.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/ZoneSettingsBuilder.java index a6b11377a91..efbf6d4051e 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/ZoneSettingsBuilder.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/ZoneSettingsBuilder.java @@ -14,6 +14,7 @@ package org.openhab.binding.tado.internal.builder; import java.io.IOException; +import org.openhab.binding.tado.internal.TadoBindingConstants; import org.openhab.binding.tado.internal.TadoBindingConstants.FanSpeed; import org.openhab.binding.tado.internal.TadoBindingConstants.HvacMode; import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit; @@ -30,7 +31,11 @@ import org.openhab.binding.tado.internal.handler.TadoZoneHandler; */ public abstract class ZoneSettingsBuilder { public static ZoneSettingsBuilder of(TadoZoneHandler zoneHandler) { - switch (zoneHandler.getZoneType()) { + TadoBindingConstants.ZoneType zoneType = zoneHandler.getZoneType(); + if (zoneType == null) { + throw new IllegalArgumentException("Zone type is null"); + } + switch (zoneType) { case HEATING: return new HeatingZoneSettingsBuilder(); case AIR_CONDITIONING: diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java index 555d762caa8..e000fc05ff6 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java @@ -62,7 +62,8 @@ public class TadoHomeHandler extends BaseBridgeHandler { } public TemperatureUnit getTemperatureUnit() { - String temperatureUnitStr = this.thing.getProperties().get(TadoBindingConstants.PROPERTY_HOME_TEMPERATURE_UNIT); + String temperatureUnitStr = this.thing.getProperties() + .getOrDefault(TadoBindingConstants.PROPERTY_HOME_TEMPERATURE_UNIT, "CELSIUS"); return TemperatureUnit.valueOf(temperatureUnitStr); } diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java index 7abd80f27f9..87db9956996 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoZoneHandler.java @@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; import javax.measure.quantity.Temperature; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.tado.internal.TadoBindingConstants; import org.openhab.binding.tado.internal.TadoBindingConstants.OperationMode; import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit; @@ -81,9 +82,9 @@ public class TadoZoneHandler extends BaseHomeThingHandler { return this.configuration.fallbackTimerDuration; } - public ZoneType getZoneType() { + public @Nullable ZoneType getZoneType() { String zoneTypeStr = this.thing.getProperties().get(TadoBindingConstants.PROPERTY_ZONE_TYPE); - return ZoneType.valueOf(zoneTypeStr); + return zoneTypeStr != null ? ZoneType.valueOf(zoneTypeStr) : null; } public OverlayTerminationCondition getDefaultTerminationCondition() throws IOException, ApiException { diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java index c99a5f85b52..4c7931494d2 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java @@ -17,10 +17,7 @@ import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -114,8 +111,8 @@ public class TradfriGatewayHandler extends BaseBridgeHandler implements CoapCall } } else { String currentFirmware = thing.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION); - if (!isNullOrEmpty(currentFirmware) - && MIN_SUPPORTED_VERSION.compareTo(new TradfriVersion(currentFirmware)) > 0) { + if (!isNullOrEmpty(currentFirmware) && MIN_SUPPORTED_VERSION + .compareTo(new TradfriVersion(Objects.requireNonNull(currentFirmware))) > 0) { // older firmware not supported updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, String.format( diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java index 87410cce90b..0b1869dcdef 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java @@ -148,8 +148,8 @@ public abstract class VelbusThingHandler extends BaseThingHandler implements Vel byte[] subAddresses = new byte[numberOfSubAddresses]; for (int i = 0; i < numberOfSubAddresses; i++) { String propertyKey = SUB_ADDRESS + (i + 1); - if (getThing().getProperties().containsKey(propertyKey)) { - String subAddress = getThing().getProperties().get(propertyKey); + String subAddress = getThing().getProperties().get(propertyKey); + if (subAddress != null) { subAddresses[i] = hexToByte(subAddress); } else { subAddresses[i] = (byte) 0xFF; diff --git a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/handler/VenstarThermostatHandler.java b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/handler/VenstarThermostatHandler.java index a6675bb0058..f6eefee8169 100644 --- a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/handler/VenstarThermostatHandler.java +++ b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/handler/VenstarThermostatHandler.java @@ -20,13 +20,7 @@ import java.math.RoundingMode; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -365,7 +359,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler { if (!isFutureValid(localUpdatesTask)) { return; } - infoData = gson.fromJson(response, VenstarInfoData.class); + infoData = Objects.requireNonNull(gson.fromJson(response, VenstarInfoData.class)); updateUnits(infoData); updateIfChanged(CHANNEL_HEATING_SETPOINT, getHeatingSetpoint()); updateIfChanged(CHANNEL_COOLING_SETPOINT, getCoolingSetpoint()); diff --git a/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java b/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java index 02909f64f0a..7bf4950ee24 100644 --- a/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java +++ b/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java @@ -108,10 +108,12 @@ public class VigiCruesHandler extends BaseThingHandler { List> flows = new ArrayList<>(); thing.getProperties().keySet().stream().filter(key -> key.startsWith(FLOOD)).forEach(key -> { String value = thing.getProperties().get(key); - if (key.contains(FLOW)) { - flows.add(new QuantityType<>(value)); - } else { - heights.add(new QuantityType<>(value)); + if (value != null) { + if (key.contains(FLOW)) { + flows.add(new QuantityType<>(value)); + } else { + heights.add(new QuantityType<>(value)); + } } }); referenceHeights = heights.stream().distinct().sorted().collect(Collectors.toList()); diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java index 8d803772241..76c7f399ab9 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java @@ -14,6 +14,7 @@ package org.openhab.binding.volvooncall.internal.api; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -108,7 +109,7 @@ public class VocHttpApi { throw new IOException(); } else { logger.debug("Request to `{}` answered : {}", url, jsonResponse); - T responseDTO = gson.fromJson(jsonResponse, objectClass); + T responseDTO = Objects.requireNonNull(gson.fromJson(jsonResponse, objectClass)); String error = responseDTO.getErrorLabel(); if (error != null) { throw new VolvoOnCallException(error, responseDTO.getErrorDescription()); diff --git a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyForecastHandler.java b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyForecastHandler.java index fc2c7983e0a..d5dcd220dc2 100644 --- a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyForecastHandler.java +++ b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyForecastHandler.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Objects; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -207,7 +208,7 @@ public class WeatherCompanyForecastHandler extends WeatherCompanyAbstractHandler } try { logger.trace("Handler: Parsing forecast response: {}", response); - ForecastDTO forecast = gson.fromJson(response, ForecastDTO.class); + ForecastDTO forecast = Objects.requireNonNull(gson.fromJson(response, ForecastDTO.class)); logger.debug("Handler: Successfully parsed daily forecast response object"); updateStatus(ThingStatus.ONLINE); updateDailyForecast(forecast); diff --git a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyObservationsHandler.java b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyObservationsHandler.java index 164bed3c412..6ea940dda81 100644 --- a/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyObservationsHandler.java +++ b/bundles/org.openhab.binding.weathercompany/src/main/java/org/openhab/binding/weathercompany/internal/handler/WeatherCompanyObservationsHandler.java @@ -14,6 +14,7 @@ package org.openhab.binding.weathercompany.internal.handler; import static org.openhab.binding.weathercompany.internal.WeatherCompanyBindingConstants.*; +import java.util.Objects; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -136,7 +137,8 @@ public class WeatherCompanyObservationsHandler extends WeatherCompanyAbstractHan } try { logger.debug("Handler: Parsing PWS observations response: {}", response); - PwsObservationsDTO pwsObservations = gson.fromJson(response, PwsObservationsDTO.class); + PwsObservationsDTO pwsObservations = Objects + .requireNonNull(gson.fromJson(response, PwsObservationsDTO.class)); logger.debug("Handler: Successfully parsed PWS observations response object"); updateStatus(ThingStatus.ONLINE); updatePwsObservations(pwsObservations); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java index 7c20d8b0a93..5da0445306e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal; import java.net.URISyntaxException; +import java.util.Objects; import java.util.concurrent.*; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -108,7 +109,7 @@ public class WlanThermoMiniHandler extends BaseThingHandler { try { // Update objects with data from device String json = httpClient.GET(config.getUri("/app.php")).getContentAsString(); - app = gson.fromJson(json, App.class); + app = Objects.requireNonNull(gson.fromJson(json, App.class)); logger.debug("Received at /app.php: {}", json); // Update channels diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java index 16be29817b3..4adeeb1ab4b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java @@ -14,6 +14,7 @@ package org.openhab.binding.wlanthermo.internal; import java.net.URI; import java.net.URISyntaxException; +import java.util.Objects; import java.util.concurrent.*; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -134,10 +135,10 @@ public class WlanThermoNanoHandler extends BaseThingHandler { try { // Update objects with data from device String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = gson.fromJson(json, Data.class); + data = Objects.requireNonNull(gson.fromJson(json, Data.class)); logger.debug("Received at /data: {}", json); json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = gson.fromJson(json, Settings.class); + settings = Objects.requireNonNull(gson.fromJson(json, Settings.class)); logger.debug("Received at /settings: {}", json); // Update channels diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java index 5cde5abc6d4..2f45bbeddda 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java @@ -16,15 +16,9 @@ import static org.openhab.io.homekit.internal.HomekitAccessoryType.*; import static org.openhab.io.homekit.internal.HomekitCharacteristicType.*; import java.lang.reflect.InvocationTargetException; +import java.util.*; import java.util.AbstractMap.SimpleEntry; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.Map.Entry; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -368,8 +362,8 @@ public class HomekitAccessoryFactory { characteristics.forEach((type, item) -> { try { // check whether a proxyItem already exists, if not create one. - final HomekitOHItemProxy proxyItem = proxyItems.computeIfAbsent(item.getUID(), - k -> new HomekitOHItemProxy(item)); + final HomekitOHItemProxy proxyItem = Objects + .requireNonNull(proxyItems.computeIfAbsent(item.getUID(), k -> new HomekitOHItemProxy(item))); final HomekitTaggedItem optionalItem = new HomekitTaggedItem(proxyItem, accessory.getRootAccessory().getAccessoryType(), type, accessory.getRootAccessory().getRootDeviceGroupItem(), diff --git a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Scenes.java b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Scenes.java index 865c868bf48..4d885986b65 100644 --- a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Scenes.java +++ b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Scenes.java @@ -383,7 +383,7 @@ public class Scenes implements RegistryChangeListener { return NetworkUtils.singleError(cs.gson, uri, HueResponse.UNAUTHORIZED, "Not Authorized"); } - final HueStateChange changeRequest = cs.gson.fromJson(body, HueStateChange.class); + final HueStateChange changeRequest = Objects.requireNonNull(cs.gson.fromJson(body, HueStateChange.class)); Rule rule = ruleRegistry.remove(id); if (rule == null) { diff --git a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Schedules.java b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Schedules.java index 801e5583892..2d8877b6b5d 100644 --- a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Schedules.java +++ b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/Schedules.java @@ -12,11 +12,7 @@ */ package org.openhab.io.hueemulation.internal.rest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import javax.ws.rs.Consumes; @@ -285,7 +281,8 @@ public class Schedules implements RegistryChangeListener { return NetworkUtils.singleError(cs.gson, uri, HueResponse.UNAUTHORIZED, "Not Authorized"); } - final HueChangeScheduleEntry changeRequest = cs.gson.fromJson(body, HueChangeScheduleEntry.class); + final HueChangeScheduleEntry changeRequest = Objects + .requireNonNull(cs.gson.fromJson(body, HueChangeScheduleEntry.class)); Rule rule = ruleRegistry.remove(id); if (rule == null) { diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyItemRegistry.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyItemRegistry.java index 7317f27e1e0..8a699ad84e0 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyItemRegistry.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyItemRegistry.java @@ -66,14 +66,16 @@ public class DummyItemRegistry implements ItemRegistry { for (RegistryChangeListener l : listeners) { l.added(element); } - return put; + return element; } @Override public @Nullable Item update(Item element) { Item put = items.put(element.getUID(), element); - for (RegistryChangeListener l : listeners) { - l.updated(put, element); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.updated(put, element); + } } return put; } @@ -81,8 +83,10 @@ public class DummyItemRegistry implements ItemRegistry { @Override public @Nullable Item remove(String key) { Item put = items.remove(key); - for (RegistryChangeListener l : listeners) { - l.removed(put); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.removed(put); + } } return put; } @@ -139,8 +143,10 @@ public class DummyItemRegistry implements ItemRegistry { @Override public @Nullable Item remove(String itemName, boolean recursive) { Item put = items.remove(itemName); - for (RegistryChangeListener l : listeners) { - l.removed(put); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.removed(put); + } } return put; } diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyMetadataRegistry.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyMetadataRegistry.java index 3adf35711a4..127b4cba40f 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyMetadataRegistry.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyMetadataRegistry.java @@ -65,14 +65,16 @@ public class DummyMetadataRegistry implements MetadataRegistry { for (RegistryChangeListener l : listeners) { l.added(element); } - return put; + return element; } @Override public @Nullable Metadata update(Metadata element) { Metadata put = items.put(element.getUID(), element); - for (RegistryChangeListener l : listeners) { - l.updated(put, element); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.updated(put, element); + } } return put; } @@ -80,8 +82,10 @@ public class DummyMetadataRegistry implements MetadataRegistry { @Override public @Nullable Metadata remove(MetadataKey key) { Metadata put = items.remove(key); - for (RegistryChangeListener l : listeners) { - l.removed(put); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.removed(put); + } } return put; } diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyRuleRegistry.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyRuleRegistry.java index 0afee55b4b9..c2b779740e7 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyRuleRegistry.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/mocks/DummyRuleRegistry.java @@ -65,14 +65,16 @@ public class DummyRuleRegistry implements RuleRegistry { for (RegistryChangeListener l : listeners) { l.added(element); } - return put; + return element; } @Override public @Nullable Rule update(Rule element) { Rule put = items.put(element.getUID(), element); - for (RegistryChangeListener l : listeners) { - l.updated(put, element); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.updated(put, element); + } } return put; } @@ -80,8 +82,10 @@ public class DummyRuleRegistry implements RuleRegistry { @Override public @Nullable Rule remove(String key) { Rule put = items.remove(key); - for (RegistryChangeListener l : listeners) { - l.removed(put); + if (put != null) { + for (RegistryChangeListener l : listeners) { + l.removed(put); + } } return put; } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoApi.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoApi.java index 15dcf89e51e..a794eadd55c 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoApi.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoApi.java @@ -204,7 +204,7 @@ public class NeeoApi implements AutoCloseable { try (HttpRequest req = new HttpRequest()) { final HttpResponse res = req.sendGetCommand(sysInfo); if (res.getHttpCode() == HttpStatus.OK_200) { - return GSON.fromJson(res.getContent(), NeeoSystemInfo.class); + return Objects.requireNonNull(GSON.fromJson(res.getContent(), NeeoSystemInfo.class)); } else { throw res.createException(); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoUtil.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoUtil.java index 72150d9d425..034cc7b0cf5 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoUtil.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/NeeoUtil.java @@ -155,9 +155,12 @@ public class NeeoUtil { * @param s The UTF-8 encoded String to be decoded * @return the decoded String */ - public static String decodeURIComponent(String s) { - String result = null; + public static String decodeURIComponent(@Nullable String s) { + if (s == null) { + return ""; + } + String result = null; try { result = URLDecoder.decode(s, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java index 5d9738817bb..8e7feb33091 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java @@ -130,11 +130,14 @@ class OpenHabToDeviceConverter { if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thing.getUID().getBindingId())) { final Map properties = thing.getProperties(); /** The following properties have matches in org.openhab.binding.neeo.NeeoDeviceHandler.java */ - final String neeoType = StringUtils.isEmpty(properties.get("Type")) ? NeeoDeviceType.ACCESSOIRE.toString() - : properties.get("Type"); - final String manufacturer = StringUtils.isEmpty(properties.get("Manufacturer")) ? "openHAB" - : properties.get("Manufacturer"); - + String neeoType = properties.get("Type"); + if (neeoType == null || neeoType.isEmpty()) { + neeoType = NeeoDeviceType.ACCESSOIRE.toString(); + } + String manufacturer = properties.get("Manufacturer"); + if (manufacturer == null || manufacturer.isEmpty()) { + manufacturer = "openHAB"; + } final Integer standbyDelay = parseInteger(properties.getOrDefault("Standby Command Delay", "0")); final Integer switchDelay = parseInteger(properties.getOrDefault("Source Switch Delay", "0")); final Integer shutDownDelay = parseInteger(properties.getOrDefault("Shutdown Delay", "0")); diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/TokenSearch.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/TokenSearch.java index 9f20b27a8f9..25c813383df 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/TokenSearch.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/TokenSearch.java @@ -110,7 +110,7 @@ public class TokenSearch { final Map<@NonNull String, String> properties = thing.getProperties(); final String vendor = properties.get(Thing.PROPERTY_VENDOR); - if (StringUtils.isNotEmpty(vendor)) { + if (vendor != null && !vendor.isEmpty()) { score += search(vendor, needles); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ChannelUIDSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ChannelUIDSerializer.java index b74ab6cf7d8..4a5e7786eae 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ChannelUIDSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ChannelUIDSerializer.java @@ -36,12 +36,8 @@ import com.google.gson.JsonSerializer; public class ChannelUIDSerializer implements JsonSerializer, JsonDeserializer { @Override - public ChannelUID deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext context) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(context, "context cannot be null"); - + public @Nullable ChannelUID deserialize(JsonElement elm, Type type, JsonDeserializationContext context) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("Not a valid ChannelUID: (null)"); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ItemSubTypeSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ItemSubTypeSerializer.java index 24ba2ac4d21..5e9ce1371ef 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ItemSubTypeSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ItemSubTypeSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer; @NonNullByDefault public class ItemSubTypeSerializer implements JsonSerializer, JsonDeserializer { @Override - public ItemSubType deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable ItemSubType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("ItemSubType could not be parsed from null"); } @@ -50,11 +45,7 @@ public class ItemSubTypeSerializer implements JsonSerializer, JsonD } @Override - public JsonElement serialize(ItemSubType ist, @Nullable Type type, @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(ist, "ist cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(ItemSubType ist, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(ist.toString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ListUiActionSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ListUiActionSerializer.java index df461e85c24..a70636d3ee7 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ListUiActionSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/ListUiActionSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer; @NonNullByDefault public class ListUiActionSerializer implements JsonSerializer, JsonDeserializer { @Override - public ListUiAction deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable ListUiAction deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("ListUiAction could not be parsed from null"); } @@ -50,12 +45,7 @@ public class ListUiActionSerializer implements JsonSerializer, Jso } @Override - public JsonElement serialize(ListUiAction ist, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(ist, "ist cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(ListUiAction ist, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(ist.toString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoBrainDeviceSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoBrainDeviceSerializer.java index 5809b62140e..b45491f8ebf 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoBrainDeviceSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoBrainDeviceSerializer.java @@ -15,7 +15,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -54,12 +53,7 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer { private final Logger logger = LoggerFactory.getLogger(NeeoBrainDeviceSerializer.class); @Override - public JsonElement serialize(NeeoDevice device, @Nullable Type deviceType, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(device, "device cannot be null"); - Objects.requireNonNull(deviceType, "deviceType cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoDevice device, Type deviceType, JsonSerializationContext jsonContext) { final JsonObject jsonObject = new JsonObject(); final String adapterName = device.getUid().getNeeoUID(); diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoCapabilityTypeSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoCapabilityTypeSerializer.java index 8cd213909af..68550692c4c 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoCapabilityTypeSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoCapabilityTypeSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer; public class NeeoCapabilityTypeSerializer implements JsonSerializer, JsonDeserializer { @Override - public NeeoCapabilityType deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable NeeoCapabilityType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("NeeoCapabilityType could not be parsed from null"); } @@ -51,12 +46,7 @@ public class NeeoCapabilityTypeSerializer } @Override - public JsonElement serialize(NeeoCapabilityType nct, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(nct, "nct cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoCapabilityType nct, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(nct.toString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelKindSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelKindSerializer.java index fd3e6e91b16..db708aef6c4 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelKindSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelKindSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer; public class NeeoDeviceChannelKindSerializer implements JsonSerializer, JsonDeserializer { @Override - public NeeoDeviceChannelKind deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable NeeoDeviceChannelKind deserialize(JsonElement elm, Type type, + JsonDeserializationContext jsonContext) throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("NeeoDeviceChannelKind could not be parsed from null"); } @@ -51,12 +46,7 @@ public class NeeoDeviceChannelKindSerializer } @Override - public JsonElement serialize(NeeoDeviceChannelKind ndck, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(ndck, "ndck cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoDeviceChannelKind ndck, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(ndck.toString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelSerializer.java index 2e8e418be07..8de0201f8d1 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceChannelSerializer.java @@ -15,7 +15,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -77,12 +76,7 @@ public class NeeoDeviceChannelSerializer } @Override - public JsonElement serialize(NeeoDeviceChannel chnl, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(chnl, "chnl cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoDeviceChannel chnl, Type type, JsonSerializationContext jsonContext) { final JsonObject jo = new JsonObject(); jo.add("kind", jsonContext.serialize(chnl.getKind())); @@ -169,12 +163,8 @@ public class NeeoDeviceChannelSerializer } @Override - public NeeoDeviceChannel deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext context) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(context, "context cannot be null"); - + public @Nullable NeeoDeviceChannel deserialize(JsonElement elm, Type type, JsonDeserializationContext context) + throws JsonParseException { if (!(elm instanceof JsonObject)) { throw new JsonParseException("Element not an instance of JsonObject: " + elm); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceSerializer.java index 3d3b500ecb4..2cb0878d27e 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceSerializer.java @@ -84,12 +84,8 @@ public class NeeoDeviceSerializer implements JsonSerializer, JsonDes } @Override - public NeeoDevice deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable NeeoDevice deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (!(elm instanceof JsonObject)) { throw new JsonParseException("Element not an instance of JsonObject: " + elm); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceTypeSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceTypeSerializer.java index de404190077..3cfc2645a8f 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceTypeSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoDeviceTypeSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer; public class NeeoDeviceTypeSerializer implements JsonSerializer, JsonDeserializer { @Override - public NeeoDeviceType deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable NeeoDeviceType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("NeeoDeviceType could not be parsed from null"); } @@ -51,12 +46,7 @@ public class NeeoDeviceTypeSerializer implements JsonSerializer, } @Override - public JsonElement serialize(NeeoDeviceType ndt, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(ndt, "ndt cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoDeviceType ndt, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(ndt.toString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoThingUIDSerializer.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoThingUIDSerializer.java index 65317374d86..bfeb0e1e994 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoThingUIDSerializer.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/serialization/NeeoThingUIDSerializer.java @@ -13,7 +13,6 @@ package org.openhab.io.neeo.internal.serialization; import java.lang.reflect.Type; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer; public class NeeoThingUIDSerializer implements JsonSerializer, JsonDeserializer { @Override - public NeeoThingUID deserialize(@Nullable JsonElement elm, @Nullable Type type, - @Nullable JsonDeserializationContext jsonContext) throws JsonParseException { - Objects.requireNonNull(elm, "elm cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public @Nullable NeeoThingUID deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) + throws JsonParseException { if (elm.isJsonNull()) { throw new JsonParseException("Not a valid ChannelUID: (null)"); } @@ -54,12 +49,7 @@ public class NeeoThingUIDSerializer implements JsonSerializer, Jso } @Override - public JsonElement serialize(NeeoThingUID uid, @Nullable Type type, - @Nullable JsonSerializationContext jsonContext) { - Objects.requireNonNull(uid, "uid cannot be null"); - Objects.requireNonNull(type, "type cannot be null"); - Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); - + public JsonElement serialize(NeeoThingUID uid, Type type, JsonSerializationContext jsonContext) { return new JsonPrimitive(uid.getAsString()); } } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/BrainDashboardService.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/BrainDashboardService.java index cead06f6c6e..83c3b0a6f23 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/BrainDashboardService.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/BrainDashboardService.java @@ -96,33 +96,40 @@ public class BrainDashboardService extends DefaultServletService { NeeoUtil.write(resp, gson.toJson(status)); } else if (StringUtils.equalsIgnoreCase(paths[0], "blinkled")) { final String brainId = req.getParameter("brainid"); - final NeeoBrainServlet servlet = service.getServlet(brainId); - if (servlet == null) { - NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId))); + if (brainId == null) { + NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null"))); } else { - try { - servlet.getBrainApi().blinkLed(); - NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true))); - } catch (IOException e) { - NeeoUtil.write(resp, - gson.toJson(new ReturnStatus("Exception occurred blinking LED: " + e.getMessage()))); + final NeeoBrainServlet servlet = service.getServlet(brainId); + if (servlet == null) { + NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BrainID: " + brainId))); + } else { + try { + servlet.getBrainApi().blinkLed(); + NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true))); + } catch (IOException e) { + NeeoUtil.write(resp, gson + .toJson(new ReturnStatus("Exception occurred blinking LED: " + e.getMessage()))); + } } } } else if (StringUtils.equalsIgnoreCase(paths[0], "getlog")) { final String brainId = req.getParameter("brainid"); - final NeeoBrainServlet servlet = service.getServlet(brainId); - if (servlet == null) { - NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId))); + if (brainId == null) { + NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null"))); } else { - try { - final String log = servlet.getBrainApi().getLog(); - NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true, log))); - } catch (IOException e) { - NeeoUtil.write(resp, - gson.toJson(new ReturnStatus("Exception occurred getting log: " + e.getMessage()))); + final NeeoBrainServlet servlet = service.getServlet(brainId); + if (servlet == null) { + NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId))); + } else { + try { + final String log = servlet.getBrainApi().getLog(); + NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true, log))); + } catch (IOException e) { + NeeoUtil.write(resp, + gson.toJson(new ReturnStatus("Exception occurred getting log: " + e.getMessage()))); + } } } - } else { logger.debug("Unknown get path: {}", StringUtils.join(paths, ',')); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/NeeoBrainSearchService.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/NeeoBrainSearchService.java index ca4e26b3361..ec288f026c3 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/NeeoBrainSearchService.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/servletservices/NeeoBrainSearchService.java @@ -109,7 +109,10 @@ public class NeeoBrainSearchService extends DefaultServletService { final String path = StringUtils.lowerCase(paths[1]); if (StringUtils.equalsIgnoreCase(path, "search")) { - doSearch(req.getQueryString(), resp); + String queryString = req.getQueryString(); + if (queryString != null) { + doSearch(queryString, resp); + } } else if (StringUtils.equalsIgnoreCase(path, "adapterdefinition") && paths.length >= 3) { doAdapterDefinition(paths[2], resp); } else { diff --git a/bundles/org.openhab.persistence.dynamodb/src/main/java/org/openhab/persistence/dynamodb/internal/DynamoDBPersistenceService.java b/bundles/org.openhab.persistence.dynamodb/src/main/java/org/openhab/persistence/dynamodb/internal/DynamoDBPersistenceService.java index 97ee8f0f4b2..f6d5dc4bf98 100644 --- a/bundles/org.openhab.persistence.dynamodb/src/main/java/org/openhab/persistence/dynamodb/internal/DynamoDBPersistenceService.java +++ b/bundles/org.openhab.persistence.dynamodb/src/main/java/org/openhab/persistence/dynamodb/internal/DynamoDBPersistenceService.java @@ -422,7 +422,7 @@ public class DynamoDBPersistenceService extends AbstractBufferedPersistenceServi String tableName = tableNameResolver.fromItem(dynamoItem); Deque> batch = batchesByTable.computeIfAbsent(tableName, new Function<>() { @Override - public Deque> apply(@Nullable String t) { + public @Nullable Deque> apply(@Nullable String t) { return new ArrayDeque<>(); } }); diff --git a/bundles/org.openhab.persistence.dynamodb/src/test/java/org/openhab/persistence/dynamodb/internal/AbstractDynamoDBItemSerializationTest.java b/bundles/org.openhab.persistence.dynamodb/src/test/java/org/openhab/persistence/dynamodb/internal/AbstractDynamoDBItemSerializationTest.java index 6900a981c49..b22c45d198a 100644 --- a/bundles/org.openhab.persistence.dynamodb/src/test/java/org/openhab/persistence/dynamodb/internal/AbstractDynamoDBItemSerializationTest.java +++ b/bundles/org.openhab.persistence.dynamodb/src/test/java/org/openhab/persistence/dynamodb/internal/AbstractDynamoDBItemSerializationTest.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.util.Objects; import java.util.TimeZone; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -73,6 +74,8 @@ public class AbstractDynamoDBItemSerializationTest { assertEquals("item1", dbItem.getName()); assertEquals(date, dbItem.getTime()); Object actualState = dbItem.getState(); + assertNotNull(actualState); + Objects.requireNonNull(actualState); if (expectedState instanceof BigDecimal) { BigDecimal expectedRounded = DynamoDBBigDecimalItem.loseDigits(((BigDecimal) expectedState)); assertEquals(0, expectedRounded.compareTo((BigDecimal) actualState), diff --git a/bundles/org.openhab.persistence.mapdb/src/test/java/org/openhab/persistence/mapdb/StateTypeAdapterTest.java b/bundles/org.openhab.persistence.mapdb/src/test/java/org/openhab/persistence/mapdb/StateTypeAdapterTest.java index bf195dfde05..af59fb40dd8 100644 --- a/bundles/org.openhab.persistence.mapdb/src/test/java/org/openhab/persistence/mapdb/StateTypeAdapterTest.java +++ b/bundles/org.openhab.persistence.mapdb/src/test/java/org/openhab/persistence/mapdb/StateTypeAdapterTest.java @@ -17,6 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigDecimal; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -75,7 +76,7 @@ public class StateTypeAdapterTest { @MethodSource public void readWriteRoundtripShouldRecreateTheWrittenState(State state) { String json = mapper.toJson(state); - State actual = mapper.fromJson(json, State.class); + State actual = Objects.requireNonNull(mapper.fromJson(json, State.class)); assertThat(actual, is(equalTo(state))); } diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/charts/RRD4jChartServlet.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/charts/RRD4jChartServlet.java index 8269e7e3585..1eb7529c64d 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/charts/RRD4jChartServlet.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/charts/RRD4jChartServlet.java @@ -17,10 +17,7 @@ import java.awt.Font; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; +import java.util.*; import javax.imageio.ImageIO; import javax.servlet.Servlet; @@ -126,12 +123,12 @@ public class RRD4jChartServlet implements Servlet, ChartProvider { int width = 480; try { - width = Integer.parseInt(req.getParameter("w")); + width = Integer.parseInt(Objects.requireNonNull(req.getParameter("w"))); } catch (Exception e) { } int height = 240; try { - height = Integer.parseInt(req.getParameter("h")); + height = Integer.parseInt(Objects.requireNonNull(req.getParameter("h"))); } catch (Exception e) { } Long period = PERIODS.get(req.getParameter("period")); diff --git a/bundles/pom.xml b/bundles/pom.xml index 678876f3984..44ae4c02d5c 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -335,7 +335,7 @@ org.lastnpe.eea eea-all - 2.1.0 + ${eea.version} @@ -504,7 +504,7 @@ org.lastnpe.eea eea-all - 2.1.0 + ${eea.version} true diff --git a/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java b/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java index 2b9397f0d29..706b9f44e4f 100644 --- a/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java +++ b/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java @@ -20,11 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import static org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import java.util.concurrent.ScheduledFuture; import java.util.function.Consumer; @@ -207,6 +203,7 @@ public class ModbusDataHandlerTest extends AbstractModbusOSGiTest { assertThat(String.format("Could not determine correct item type for %s", channelId), item, is(notNullValue())); assertNotNull(item); + Objects.requireNonNull(item); addItem(item); toBeLinked.put(itemName, channelUID); } diff --git a/itests/pom.xml b/itests/pom.xml index 5930e170f18..f079200a89f 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -91,7 +91,7 @@ org.lastnpe.eea eea-all - 2.1.0 + ${eea.version} true diff --git a/pom.xml b/pom.xml index 6cdc99711a1..48e68d21f9b 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ src/main/feature/feature.xml 2.0.3 + 2.2.1 @@ -289,8 +290,8 @@ Import-Package: \\ ${project.build.directory}/dependency - -err:+nullAnnot(org.eclipse.jdt.annotation.Nullable|org.eclipse.jdt.annotation.NonNull|org.eclipse.jdt.annotation.NonNullByDefault),+inheritNullAnnot,-nullUncheckedConversion - -warn:+null,+inheritNullAnnot,+nullAnnotConflict,-nullUncheckedConversion,+nullAnnotRedundant,+nullDereference + -err:+nullAnnot(org.eclipse.jdt.annotation.Nullable|org.eclipse.jdt.annotation.NonNull|org.eclipse.jdt.annotation.NonNullByDefault),+inheritNullAnnot,+nullAnnotConflict,-nullUncheckedConversion + -warn:+null,+inheritNullAnnot,-nullUncheckedConversion,+nullAnnotRedundant,+nullDereference true true