From 863d0bf4032bba1b9199b8aa1a68981f2ed2fdc1 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 9 Mar 2020 14:41:52 +0100 Subject: [PATCH] Fix NPE in ServiceDiscoveryManager --- .../java/org/jivesoftware/smack/packet/StanzaBuilder.java | 8 ++++++++ .../smackx/disco/ServiceDiscoveryManager.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java index 3539d22bd..cff077e29 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java @@ -162,6 +162,14 @@ public abstract class StanzaBuilder> implements Stanz return getThis(); } + public final B addOptExtensions(Collection extensionElements) { + if (extensionElements == null) { + return getThis(); + } + + return addExtensions(extensionElements); + } + public final B addExtensions(Collection extensionElements) { for (ExtensionElement extensionElement : extensionElements) { addExtension(extensionElement); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java index 62fc38d1d..a009d260b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java @@ -178,7 +178,7 @@ public final class ServiceDiscoveryManager extends Manager { // Add node identities responseBuilder.addIdentities(nodeInformationProvider.getNodeIdentities()); // Add packet extensions - responseBuilder.addExtensions(nodeInformationProvider.getNodePacketExtensions()); + responseBuilder.addOptExtensions(nodeInformationProvider.getNodePacketExtensions()); } else { // Return error since specified node was not found responseBuilder.ofType(IQ.Type.error);