From f61d0aa22beb7d3cd087ac3605bc88bf999bfead Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 2 Feb 2024 09:54:15 -0800 Subject: [PATCH 1/2] publishPacket cannot be null at this point --- samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java b/samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java index 721491997..8200df50b 100644 --- a/samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java +++ b/samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java @@ -93,10 +93,6 @@ static final class SamplePublishEvents implements Mqtt5ClientOptions.PublishEven @Override public void onMessageReceived(Mqtt5Client client, PublishReturn publishReturn) { PublishPacket publishPacket = publishReturn.getPublishPacket(); - if (publishPacket == null) { - messagesReceived.countDown(); - return; - } System.out.println("Publish received on topic: " + publishPacket.getTopic()); System.out.println("Message: " + new String(publishPacket.getPayload())); @@ -123,7 +119,6 @@ public static void main(String[] args) { CommandLineUtils.SampleCommandLineData cmdData = CommandLineUtils.getInputForIoTSample("Mqtt5PubSub", args); try { - /* Create a client based on desired connection type */ SampleLifecycleEvents lifecycleEvents = new SampleLifecycleEvents(); SamplePublishEvents publishEvents = new SamplePublishEvents(cmdData.input_count); Mqtt5Client client; From 2d26c41d11de0ce96e42bbc6d3bd963911d08e95 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Tue, 6 Feb 2024 13:55:18 -0800 Subject: [PATCH 2/2] shared sub null check --- .../sharedsubscription/SharedSubscription.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/samples/Mqtt5/SharedSubscription/src/main/java/sharedsubscription/SharedSubscription.java b/samples/Mqtt5/SharedSubscription/src/main/java/sharedsubscription/SharedSubscription.java index 0bc19745f..7fed48ece 100644 --- a/samples/Mqtt5/SharedSubscription/src/main/java/sharedsubscription/SharedSubscription.java +++ b/samples/Mqtt5/SharedSubscription/src/main/java/sharedsubscription/SharedSubscription.java @@ -118,16 +118,14 @@ public void onMessageReceived(Mqtt5Client client, PublishReturn publishReturn) { System.out.println("[" + sampleClient.name + "] Received a publish"); } PublishPacket publishPacket = publishReturn.getPublishPacket(); - if (publishPacket != null) { - System.out.println("\tPublish received on topic: " + publishPacket.getTopic()); - System.out.println("\tMessage: " + new String(publishPacket.getPayload())); - - List packetProperties = publishPacket.getUserProperties(); - if (packetProperties != null) { - for (int i = 0; i < packetProperties.size(); i++) { - UserProperty property = packetProperties.get(i); - System.out.println("\t\twith UserProperty: (" + property.key + ", " + property.value + ")"); - } + System.out.println("\tPublish received on topic: " + publishPacket.getTopic()); + System.out.println("\tMessage: " + new String(publishPacket.getPayload())); + + List packetProperties = publishPacket.getUserProperties(); + if (packetProperties != null) { + for (int i = 0; i < packetProperties.size(); i++) { + UserProperty property = packetProperties.get(i); + System.out.println("\t\twith UserProperty: (" + property.key + ", " + property.value + ")"); } } }