]> git.basschouten.com Git - openhab-addons.git/commitdiff
Fix NPE on shutdown when Thing disabled and fix a bunch of warnings (#13215)
authormlobstein <michael.lobstein@gmail.com>
Thu, 4 Aug 2022 13:56:52 +0000 (08:56 -0500)
committerGitHub <noreply@github.com>
Thu, 4 Aug 2022 13:56:52 +0000 (15:56 +0200)
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
15 files changed:
bundles/org.openhab.binding.atlona/README.md
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerCallback.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerFactory.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/StatefulHandlerCallback.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/discovery/AtlonaDiscovery.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/handler/AtlonaCapabilities.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketSession.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketSessionListener.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Capabilities.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Config.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Constants.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Handler.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3PortocolHandler.java
bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Utilities.java

index cde05a2ffe933412d93fb1308f7dcbb5861eb837..6bf50b568f1b5dacdce47b38d6c2ca9a41eb3eeb 100644 (file)
@@ -211,19 +211,19 @@ As of firmware 1.6.8 (rev 14),
 
 Here is an example with minimal configuration parameters (using default values with no telnet login):
 
-```java
+```
 atlona:pro3-88m:home [ ipAddress="192.168.1.30" ]
 ```
 
 Here is another example with minimal configuration parameters (using default values with telnet login):
 
-```java
+```
 atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345" ]
 ```
 
 Here is a full configuration example:
 
-```java
+```
 atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345", polling=600, ping=30, retryPolling=10 ]
 ```
 
@@ -231,7 +231,7 @@ atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345"
 
 Here is an example of items for the AT-UHD-PRO33-88M:
 
-```java
+```
 Switch Atlona_Power "Power" { channel = "atlona:pro3-88m:home:primary#power" }
 Switch Atlona_PanelLock "Panel Lock" { channel = "atlona:pro3-88m:home:primary#panellock" }
 Switch Atlona_Presets "Preset Command" { channel = "atlona:pro3-88m:home:primary#presetcmd" }
@@ -274,7 +274,7 @@ Switch Atlona_VolumeMute6 "Mute 6" { channel = "atlona:pro3-88m:home:volume1#vol
 
 ### SiteMap
 
-```perl
+```
 sitemap demo label="Main Menu" {
     Frame label="Atlona" {
         Text label="Device" {
@@ -332,7 +332,7 @@ Be sure they are in sync with the mappings above.
 
 ### atlonainputports.map
 
-```text
+```
 1=CableBox
 2=BluRay Player
 3=Roku
@@ -347,7 +347,7 @@ NULL=-
 
 ### atlonaoutputports.map
 
-```text
+```
 1=Living Room
 2=Master Bed
 3=Kitchen
index d24f33a72e455baa79cdd30fcd4c254b011a4ed3..47d3b7178e0fab23da105c3dd8c5ad76fb514ea8 100644 (file)
@@ -12,7 +12,8 @@
  */
 package org.openhab.binding.atlona.internal;
 
-import org.openhab.binding.atlona.internal.handler.AtlonaHandler;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingStatusDetail;
 import org.openhab.core.types.State;
@@ -23,6 +24,7 @@ import org.openhab.core.types.State;
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 public interface AtlonaHandlerCallback {
     /**
      * Callback to the {@link AtlonaHandler} to update the status of the thing.
@@ -31,7 +33,7 @@ public interface AtlonaHandlerCallback {
      * @param detail a non-null {@link org.openhab.core.thing.ThingStatusDetail}
      * @param msg a possibly null, possibly empty message
      */
-    void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg);
+    void statusChanged(ThingStatus status, ThingStatusDetail detail, @Nullable String msg);
 
     /**
      * Callback to the {@link AtlonaHandler} to update the state of an item
index b26871a356a05caa3c75b3e14fa7b18546258fff..ccbcbd7910deac54143db515cf91ed373bb8421c 100644 (file)
@@ -17,6 +17,8 @@ import static org.openhab.binding.atlona.internal.AtlonaBindingConstants.*;
 import java.util.Collections;
 import java.util.Set;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Capabilities;
 import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Handler;
 import org.openhab.core.thing.Thing;
@@ -35,6 +37,7 @@ import org.slf4j.LoggerFactory;
  * @author Tim Roberts - Initial contribution
  * @author Michael Lobstein - Add support for AT-PRO3HD66M
  */
+@NonNullByDefault
 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.atlona")
 public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
 
@@ -62,7 +65,7 @@ public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
      * Creates the handler for the given thing given its thingTypeUID
      */
     @Override
-    protected ThingHandler createHandler(Thing thing) {
+    protected @Nullable ThingHandler createHandler(Thing thing) {
         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
 
         if (thingTypeUID.equals(THING_TYPE_PRO3_44M)) {
index 2d40b92db76e53231ab47eac8d4beb4b875e2bb3..68dd279ab4b106a4e28388474f0fb04538fef698 100644 (file)
@@ -88,7 +88,7 @@ public class StatefulHandlerCallback implements AtlonaHandlerCallback {
      */
     @Override
     public void stateChanged(String channelId, State state) {
-        if (channelId == null || "".equals(channelId)) {
+        if ("".equals(channelId)) {
             return;
         }
 
index 226397bf4cabba919bb6e2c82f343c24bf5b4d37..29da2aee7f5f74e94004b64f8de846780991f872 100644 (file)
@@ -137,7 +137,7 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
                                 multiSocket.receive(receivePacket);
 
                                 String message = new String(receivePacket.getData()).trim();
-                                if (message != null && message.length() > 0) {
+                                if (message.length() > 0) {
                                     messageReceive(message);
                                 }
                             } catch (SocketTimeoutException e) {
@@ -196,17 +196,17 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
             if (idx > 0) {
                 String name = msg.substring(0, idx);
 
-                if (name.equalsIgnoreCase("Host")) {
+                if ("Host".equalsIgnoreCase(name)) {
                     host = msg.substring(idx + 1).trim().replaceAll("\"", "");
                     int sep = host.indexOf('_');
                     if (sep >= 0) {
                         host = host.substring(sep + 1);
                     }
-                } else if (name.equalsIgnoreCase("Model")) {
+                } else if ("Model".equalsIgnoreCase(name)) {
                     model = msg.substring(idx + 1).trim().replaceAll("\"", "");
-                } else if (name.equalsIgnoreCase("Manufacturer")) {
+                } else if ("Manufacturer".equalsIgnoreCase(name)) {
                     manufacturer = msg.substring(idx + 1).trim().replaceAll("\"", "");
-                } else if (name.equalsIgnoreCase("From")) {
+                } else if ("From".equalsIgnoreCase(name)) {
                     from = msg.substring(idx + 1).trim().replaceAll("\"", "");
                     int sep = from.indexOf(':');
                     if (sep >= 0) {
@@ -223,13 +223,13 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
 
         if (host != null && model != null && from != null) {
             ThingTypeUID typeId = null;
-            if (model.equalsIgnoreCase("AT-UHD-PRO3-44M")) {
+            if ("AT-UHD-PRO3-44M".equalsIgnoreCase(model)) {
                 typeId = THING_TYPE_PRO3_44M;
-            } else if (model.equalsIgnoreCase("AT-UHD-PRO3-66M")) {
+            } else if ("AT-UHD-PRO3-66M".equalsIgnoreCase(model)) {
                 typeId = THING_TYPE_PRO3_66M;
-            } else if (model.equalsIgnoreCase("AT-UHD-PRO3-88M")) {
+            } else if ("AT-UHD-PRO3-88M".equalsIgnoreCase(model)) {
                 typeId = THING_TYPE_PRO3_88M;
-            } else if (model.equalsIgnoreCase("AT-UHD-PRO3-1616M")) {
+            } else if ("AT-UHD-PRO3-1616M".equalsIgnoreCase(model)) {
                 typeId = THING_TYPE_PRO3_1616M;
             } else {
                 logger.warn("Unknown model #: {}", model);
index 9123de54963a057ee6881855428dc67fd2f6e9f3..0289bd23fe7268849b741426863adfd2ef21438a 100644 (file)
  */
 package org.openhab.binding.atlona.internal.handler;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * Any model specific capabilities class should inherit from this base class. Currently doesn't provide any generic
  * functionality.
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 public abstract class AtlonaCapabilities {
 
 }
index 4819089dbe81685453dd912593cb9c30eb2d20d6..55ce9e04314e28d29bab9ccbe842ca0b21bf545a 100644 (file)
@@ -100,9 +100,6 @@ public class SocketChannelSession implements SocketSession {
 
     @Override
     public void addListener(SocketSessionListener listener) {
-        if (listener == null) {
-            throw new IllegalArgumentException("listener cannot be null");
-        }
         listeners.add(listener);
     }
 
@@ -166,10 +163,6 @@ public class SocketChannelSession implements SocketSession {
 
     @Override
     public synchronized void sendCommand(String command) throws IOException {
-        if (command == null) {
-            throw new IllegalArgumentException("command cannot be null");
-        }
-
         if (!isConnected()) {
             throw new IOException("Cannot send message - disconnected");
         }
index e554896e277eaf0869564910989b4e152fcb9ef2..e22bcb74bffeb2c9255c8610e3e9f2321700938b 100644 (file)
@@ -14,12 +14,15 @@ package org.openhab.binding.atlona.internal.net;
 
 import java.io.IOException;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * This is a socket session interface that defines the contract for a socket session. A socket session will initiate
  * communications with the underlying device and provide message back via the {@link SocketSessionListener}
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 public interface SocketSession {
 
     /**
index 6658596f6b8d732cdbac8db0af46277e1b874f3a..5a6e3b06dc3f54b56c3fbe0699c9bf9d4881fdcf 100644 (file)
  */
 package org.openhab.binding.atlona.internal.net;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * Interface defining a listener to a {@link SocketSession} that will receive responses and/or exceptions from the
  * socket
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 public interface SocketSessionListener {
     /**
      * Called when a command has completed with the response for the command
index cd32170cf569b092d3f720210d076b85f8055684..bf5c88ac49a564cc0f3b97f47d8b9c3105ad93a3 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.atlona.internal.handler.AtlonaCapabilities;
 
 /**
@@ -25,6 +26,7 @@ import org.openhab.binding.atlona.internal.handler.AtlonaCapabilities;
  * @author Tim Roberts - Initial contribution
  * @author Michael Lobstein - Add support for AT-PRO3HD66M
  */
+@NonNullByDefault
 public class AtlonaPro3Capabilities extends AtlonaCapabilities {
 
     /**
@@ -57,10 +59,6 @@ public class AtlonaPro3Capabilities extends AtlonaCapabilities {
     public AtlonaPro3Capabilities(int nbrPowerPorts, int nbrAudioPorts, Set<Integer> hdmiPorts, boolean isUHDModel) {
         super();
 
-        if (hdmiPorts == null) {
-            throw new IllegalArgumentException("hdmiPorts cannot be null");
-        }
-
         if (hdmiPorts.isEmpty()) {
             throw new IllegalArgumentException("hdmiPorts cannot be empty");
         }
index 6b9ed3ac48d188d2f5a56f5c0c179e19420c89a3..517c7cb8a0f7d02ad68b6ddfc1b0753749221d1c 100644 (file)
@@ -12,8 +12,6 @@
  */
 package org.openhab.binding.atlona.internal.pro3;
 
-import org.openhab.binding.atlona.internal.discovery.AtlonaDiscovery;
-
 /**
  * Configuration class for the Atlona Pro3 line of switchers
  *
index 05805621ad479b3871ac372a10dddd5b8ecedc96..a8f5f5283f77619370761bca7a19892382dd560f 100644 (file)
  */
 package org.openhab.binding.atlona.internal.pro3;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * The {@link AtlonaPro3Binding} class defines common constants, which are
  * used across the whole binding.
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 class AtlonaPro3Constants {
 
     // Properties
@@ -44,7 +47,6 @@ class AtlonaPro3Constants {
 
     static final String CHANNEL_VOLUME = "volume";
     static final String CHANNEL_VOLUME_MUTE = "volumemute";
-    // static final String CHANNEL_RS232 = "rs232cmd";
 
     static final String CONFIG_HOSTNAME = "hostname";
     static final String CONFIG_OUTPUT = "output";
index c949f3cb0adf5445e45282c684d97e9b1410a2a4..5bfc2d434a02f58c202f9e5833f32ec4b862c58f 100644 (file)
@@ -554,10 +554,12 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
             ping = null;
         }
 
-        try {
-            session.disconnect();
-        } catch (IOException e) {
-            // ignore - we don't care
+        if (session != null) {
+            try {
+                session.disconnect();
+            } catch (IOException e) {
+                // ignore - we don't care
+            }
         }
 
         if (retryConnection) {
@@ -588,16 +590,10 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
     /**
      * Simple gets the {@link AtlonaPro3Config} from the {@link Thing} and will set the status to offline if not found.
      *
-     * @return a possible null {@link AtlonaPro3Config}
+     * @return {@link AtlonaPro3Config}
      */
     private AtlonaPro3Config getAtlonaConfig() {
-        final AtlonaPro3Config config = getThing().getConfiguration().as(AtlonaPro3Config.class);
-
-        if (config == null) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
-        }
-
-        return config;
+        return getThing().getConfiguration().as(AtlonaPro3Config.class);
     }
 
     /**
index 5e938939a824f2ac6399ec4b1e4dd7fd2295dbed..61b86462872df89eefe16e098a18016543cc8158 100644 (file)
@@ -199,7 +199,7 @@ class AtlonaPro3PortocolHandler {
         String response;
         try {
             response = callback.getResponse();
-            if (!response.equals("")) {
+            if (!"".equals(response)) {
                 logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
             }
         } catch (Exception e) {
@@ -223,13 +223,13 @@ class AtlonaPro3PortocolHandler {
 
         // We should have been presented with a new "\r\nLogin: "
         response = callback.getResponse();
-        if (!response.equals("")) {
+        if (!"".equals(response)) {
             logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
         }
 
         // Get the new "Login: " prompt response
         response = callback.getResponse();
-        if (response.equals(RSP_LOGIN)) {
+        if (RSP_LOGIN.equals(response)) {
             if (config.getUserName() == null || config.getUserName().trim().length() == 0) {
                 return "Atlona PRO3 has enabled Telnet/IP Login but no username was provided in the configuration.";
             }
@@ -244,12 +244,12 @@ class AtlonaPro3PortocolHandler {
         response = callback.getResponse();
 
         // Burn the empty response if we got one (
-        if (response.equals("")) {
+        if ("".equals(response)) {
             response = callback.getResponse();
         }
-        if (!response.equals(RSP_PASSWORD)) {
+        if (!RSP_PASSWORD.equals(response)) {
             // If we got another login response, username wasn't valid
-            if (response.equals(RSP_LOGIN)) {
+            if (RSP_LOGIN.equals(response)) {
                 return "Username " + config.getUserName() + " is not a valid user on the atlona";
             }
             return "Atlona protocol violation - invalid response to a login: " + response;
@@ -270,7 +270,7 @@ class AtlonaPro3PortocolHandler {
         // Send an invalid command to see if we get the failed command response
 
         // First make sure we had an empty response (the "\r\n" part)
-        if (!response.equals("")) {
+        if (!"".equals(response)) {
             logger.debug("Atlona protocol violation - not an empty response after password: '{}'", response);
         }
 
@@ -307,7 +307,7 @@ class AtlonaPro3PortocolHandler {
         String response;
         try {
             response = callback.getResponse();
-            if (!response.equals("")) {
+            if (!"".equals(response)) {
                 logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
             }
         } catch (Exception e) {
@@ -335,7 +335,7 @@ class AtlonaPro3PortocolHandler {
 
             // Check for an empty response after the login prompt (the "\r\n" part)
             response = callback.getResponse();
-            if (!response.equals("")) {
+            if (!"".equals(response)) {
                 logger.debug("Atlona protocol violation - not an empty response after password: '{}'", response);
             }
 
@@ -907,7 +907,7 @@ class AtlonaPro3PortocolHandler {
                 // could be "off" (if mirror off), "on"/"Out" (with 3rd group representing out)
                 String oper = (m.group(2) == null ? "" : m.group(2).trim()).toLowerCase();
 
-                if (oper.equals("off")) {
+                if ("off".equals(oper)) {
                     callback.stateChanged(AtlonaPro3Utilities.createChannelID(AtlonaPro3Constants.GROUP_MIRROR,
                             hdmiPortNbr, AtlonaPro3Constants.CHANNEL_PORTMIRRORENABLED), OnOffType.OFF);
                 } else {
@@ -1088,7 +1088,7 @@ class AtlonaPro3PortocolHandler {
 
         @Override
         public void responseReceived(String response) {
-            if (response == null || response.isEmpty()) {
+            if (response.isEmpty()) {
                 return;
             }
 
index ad5e6e9802bf53a3e7aaf30847468bcb7ca5859a..836ae6daed2479ef33351c92d6177847082302e5 100644 (file)
  */
 package org.openhab.binding.atlona.internal.pro3;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  *
  * @author Tim Roberts - Initial contribution
  */
+@NonNullByDefault
 public class AtlonaPro3Utilities {
     /**
      * Helper method to create a channel id from a group with no port number attached