Skip to content

Commit

Permalink
Remove needless null check (#537)
Browse files Browse the repository at this point in the history
* remove unnecessary publish packet null checks in samples
  • Loading branch information
sbSteveK authored Feb 6, 2024
1 parent 2830ca8 commit 787779b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
5 changes: 0 additions & 5 deletions samples/Mqtt5/PubSub/src/main/java/pubsub/PubSub.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserProperty> 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<UserProperty> 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 + ")");
}
}
}
Expand Down

0 comments on commit 787779b

Please sign in to comment.