From 86ea027301fee9d715861885d3cec2096b8f84af Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 26 Jan 2015 20:36:55 +0100 Subject: [PATCH] Add StringUtils.requireNotNullOrEmpty and Objects.requireNonNull and use this in a few places. --- .../smack/AbstractXMPPConnection.java | 27 ++++++++----------- .../java/org/jivesoftware/smack/Manager.java | 7 ++--- .../jivesoftware/smack/filter/AndFilter.java | 13 +++------ .../jivesoftware/smack/filter/OrFilter.java | 13 +++------ .../smack/filter/PacketExtensionFilter.java | 5 ++-- .../smack/filter/PacketIDFilter.java | 4 +-- .../smack/filter/ThreadFilter.java | 4 +-- .../jivesoftware/smack/packet/ErrorIQ.java | 6 ++--- .../org/jivesoftware/smack/packet/IQ.java | 6 ++--- .../smack/sasl/packet/SaslStreamElements.java | 12 +++------ .../org/jivesoftware/smack/util/Objects.java | 27 +++++++++++++++++++ .../jivesoftware/smack/util/StringUtils.java | 7 +++++ .../smack/util/dns/HostAddress.java | 4 +-- .../smack/util/stringencoder/Base64.java | 7 +++-- .../stringencoder/Base64UrlSafeEncoder.java | 8 +++--- .../smackx/disco/packet/DiscoverInfo.java | 14 +++------- .../smackx/iqversion/packet/Version.java | 12 +++------ .../smackx/muc/MultiUserChat.java | 12 +++------ 18 files changed, 88 insertions(+), 100 deletions(-) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 349df3f17..f38eae26d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -75,6 +75,7 @@ import org.jivesoftware.smack.parsing.UnparsablePacket; import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.util.DNSUtil; +import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.SmackExecutorThreadFactory; @@ -469,8 +470,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { */ public synchronized void login(CharSequence username, String password, String resource) throws XMPPException, SmackException, IOException { - if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) { - throw new IllegalArgumentException("Username must not be null or empty"); + if (!config.allowNullOrEmptyUsername) { + StringUtils.requireNotNullOrEmpty(username, "Username must not be null or empty"); } throwNotConnectedExceptionIfAppropriate(); throwAlreadyLoggedInExceptionIfAppropriate(); @@ -618,9 +619,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { @Override public void sendPacket(Packet packet) throws NotConnectedException { - if (packet == null) { - throw new IllegalArgumentException("Packet must not be null"); - } + Objects.requireNonNull(packet, "Packet must not be null"); + throwNotConnectedExceptionIfAppropriate(); switch (fromMode) { case OMITTED: @@ -1419,17 +1419,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { public void sendStanzaWithResponseCallback(Packet stanza, PacketFilter replyFilter, final PacketListener callback, final ExceptionCallback exceptionCallback, long timeout) throws NotConnectedException { - if (stanza == null) { - throw new IllegalArgumentException("stanza must not be null"); - } - if (replyFilter == null) { - // While Smack allows to add PacketListeners with a PacketFilter value of 'null', we - // disallow it here in the async API as it makes no sense - throw new IllegalArgumentException("replyFilter must not be null"); - } - if (callback == null) { - throw new IllegalArgumentException("callback must not be null"); - } + Objects.requireNonNull(stanza, "stanza must not be null"); + // While Smack allows to add PacketListeners with a PacketFilter value of 'null', we + // disallow it here in the async API as it makes no sense + Objects.requireNonNull(replyFilter, "replyFilter must not be null"); + Objects.requireNonNull(callback, "callback must not be null"); + final PacketListener packetListener = new PacketListener() { @Override public void processPacket(Packet packet) throws NotConnectedException { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Manager.java b/smack-core/src/main/java/org/jivesoftware/smack/Manager.java index a999d36a9..8f9299832 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Manager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/Manager.java @@ -18,14 +18,15 @@ package org.jivesoftware.smack; import java.lang.ref.WeakReference; +import org.jivesoftware.smack.util.Objects; + public abstract class Manager { final WeakReference weakConnection; public Manager(XMPPConnection connection) { - if (connection == null) { - throw new IllegalArgumentException("XMPPConnection must not be null"); - } + Objects.requireNonNull(connection, "XMPPConnection must not be null"); + weakConnection = new WeakReference(connection); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java index 0396265ae..200b364e0 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.util.Objects; /** * Implements the logical AND operation over two or more packet filters. @@ -50,13 +51,9 @@ public class AndFilter implements PacketFilter { * @param filters the filters to add. */ public AndFilter(PacketFilter... filters) { - if (filters == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filters, "Parameter must not be null."); for(PacketFilter filter : filters) { - if(filter == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filter, "Parameter must not be null."); } this.filters = new ArrayList(Arrays.asList(filters)); } @@ -68,9 +65,7 @@ public class AndFilter implements PacketFilter { * @param filter a filter to add to the filter list. */ public void addFilter(PacketFilter filter) { - if (filter == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filter, "Parameter must not be null."); filters.add(filter); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java index 7c52ed761..e85af68d6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.util.Objects; /** * Implements the logical OR operation over two or more packet filters. In @@ -50,13 +51,9 @@ public class OrFilter implements PacketFilter { * @param filters the filters to add. */ public OrFilter(PacketFilter... filters) { - if (filters == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filters, "Parameter must not be null."); for(PacketFilter filter : filters) { - if(filter == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filter, "Parameter must not be null."); } this.filters = new ArrayList(Arrays.asList(filters)); } @@ -68,9 +65,7 @@ public class OrFilter implements PacketFilter { * @param filter a filter to add to the filter list. */ public void addFilter(PacketFilter filter) { - if (filter == null) { - throw new IllegalArgumentException("Parameter must not be null."); - } + Objects.requireNonNull(filter, "Parameter must not be null."); filters.add(filter); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java index 3cb6218e4..7171e9f59 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java @@ -40,9 +40,8 @@ public class PacketExtensionFilter implements PacketFilter { * @param namespace the XML namespace of the packet extension. */ public PacketExtensionFilter(String elementName, String namespace) { - if (StringUtils.isNullOrEmpty(namespace)) { - throw new IllegalArgumentException("namespace must not be null or empty"); - } + StringUtils.requireNotNullOrEmpty(namespace, "namespace must not be null or empty"); + this.elementName = elementName; this.namespace = namespace; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java index 4c31bcdfe..86ccac342 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java @@ -44,9 +44,7 @@ public class PacketIDFilter implements PacketFilter { * @param packetID the packet ID to filter for. */ public PacketIDFilter(String packetID) { - if (StringUtils.isNullOrEmpty(packetID)) { - throw new IllegalArgumentException("Packet ID must not be null or empty."); - } + StringUtils.requireNotNullOrEmpty(packetID, "Packet ID must not be null or empty."); this.packetID = packetID; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java index ca45733ea..e18d7bae4 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java @@ -36,9 +36,7 @@ public class ThreadFilter implements PacketFilter { * @param thread the thread value to filter for. */ public ThreadFilter(String thread) { - if (StringUtils.isNullOrEmpty(thread)) { - throw new IllegalArgumentException("Thread must not be null or empty."); - } + StringUtils.requireNotNullOrEmpty(thread, "Thread must not be null or empty."); this.thread = thread; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/ErrorIQ.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/ErrorIQ.java index 62d880cba..dfc9e0e97 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/ErrorIQ.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/ErrorIQ.java @@ -16,6 +16,8 @@ */ package org.jivesoftware.smack.packet; +import org.jivesoftware.smack.util.Objects; + public class ErrorIQ extends SimpleIQ { public static final String ELEMENT = XMPPError.ERROR; @@ -29,9 +31,7 @@ public class ErrorIQ extends SimpleIQ { */ public ErrorIQ(XMPPError xmppError) { super(ELEMENT, null); - if (xmppError == null) { - throw new IllegalArgumentException("XMPPError must not be null"); - } + Objects.requireNonNull(xmppError, "XMPPError must not be null"); setType(IQ.Type.error); setError(xmppError); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java index 60e2e4587..9ca7ad4c7 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java @@ -19,6 +19,7 @@ package org.jivesoftware.smack.packet; import java.util.Locale; +import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.XmlStringBuilder; /** @@ -84,10 +85,7 @@ public abstract class IQ extends Packet { * @param type the type of the IQ packet. */ public void setType(Type type) { - if (type == null) { - throw new IllegalArgumentException("type must not be null"); - } - this.type = type; + this.type = Objects.requireNonNull(type, "type must not be null"); } /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/packet/SaslStreamElements.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/packet/SaslStreamElements.java index 8e731fabd..c86a49e03 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/packet/SaslStreamElements.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/packet/SaslStreamElements.java @@ -21,6 +21,7 @@ import java.util.Map; import org.jivesoftware.smack.packet.AbstractError; import org.jivesoftware.smack.packet.PlainStreamElement; import org.jivesoftware.smack.sasl.SASLError; +import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; @@ -37,14 +38,9 @@ public class SaslStreamElements { private final String authenticationText; public AuthMechanism(String mechanism, String authenticationText) { - if (mechanism == null) { - throw new NullPointerException("SASL mechanism shouldn't be null."); - } - if (StringUtils.isNullOrEmpty(authenticationText)) { - throw new IllegalArgumentException("SASL authenticationText must not be null or empty (RFC6120 6.4.2)"); - } - this.mechanism = mechanism; - this.authenticationText = authenticationText; + this.mechanism = Objects.requireNonNull(mechanism, "SASL mechanism shouldn't be null."); + this.authenticationText = StringUtils.requireNotNullOrEmpty(authenticationText, + "SASL authenticationText must not be null or empty (RFC6120 6.4.2)"); } @Override diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java b/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java new file mode 100644 index 000000000..fa5bd6561 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.util; + +public class Objects { + + public static T requireNonNull(T obj, String message) { + if (obj == null) { + throw new IllegalArgumentException(message); + } + return obj; + } +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java index 8a3c5aeab..5aba68d91 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java @@ -257,4 +257,11 @@ public class StringUtils { } return csOne.toString().compareTo(csTwo.toString()); } + + public static CS requireNotNullOrEmpty(CS cs, String message) { + if (isNullOrEmpty(cs)) { + throw new IllegalArgumentException(message); + } + return cs; + } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java index f0004b520..57c60c07a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java @@ -17,6 +17,7 @@ package org.jivesoftware.smack.util.dns; import org.jivesoftware.smack.SmackException.ConnectionException; +import org.jivesoftware.smack.util.Objects; public class HostAddress { private final String fqdn; @@ -42,8 +43,7 @@ public class HostAddress { * @throws IllegalArgumentException If the fqdn is null or port is out of valid range (0 - 65535). */ public HostAddress(String fqdn, int port) { - if (fqdn == null) - throw new IllegalArgumentException("FQDN is null"); + Objects.requireNonNull(fqdn, "FQDN is null"); if (port < 0 || port > 65535) throw new IllegalArgumentException( "Port must be a 16-bit unsiged integer (i.e. between 0-65535. Port was: " + port); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java index 220456be5..80b6928d6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014 Florian Schmaus + * Copyright © 2014-2015 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.jivesoftware.smack.util.stringencoder; import java.io.UnsupportedEncodingException; +import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.StringUtils; public class Base64 { @@ -25,9 +26,7 @@ public class Base64 { private static Base64.Encoder base64encoder; public static void setEncoder(Base64.Encoder encoder) { - if (encoder == null) { - throw new IllegalArgumentException("encoder must no be null"); - } + Objects.requireNonNull(encoder, "encoder must no be null"); base64encoder = encoder; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64UrlSafeEncoder.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64UrlSafeEncoder.java index 73d1c7ce8..93c3e53f1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64UrlSafeEncoder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64UrlSafeEncoder.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014 Florian Schmaus + * Copyright © 2014-2015 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,14 @@ */ package org.jivesoftware.smack.util.stringencoder; +import org.jivesoftware.smack.util.Objects; + public class Base64UrlSafeEncoder { private static StringEncoder base64UrlSafeEncoder; public static void setEncoder(StringEncoder encoder) { - if (encoder == null) { - throw new IllegalArgumentException("encoder must no be null"); - } + Objects.requireNonNull(encoder, "encoder must no be null"); base64UrlSafeEncoder = encoder; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java index 9b7e97159..e4f5ca0f6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java @@ -316,14 +316,8 @@ public class DiscoverInfo extends IQ implements Cloneable { * @param lang the entity's lang. */ public Identity(String category, String type, String name, String lang) { - if (StringUtils.isNullOrEmpty(category)) { - throw new IllegalArgumentException("category cannot be null"); - } - if (StringUtils.isNullOrEmpty(type)) { - throw new IllegalArgumentException("type cannot be null"); - } - this.category = category; - this.type = type; + this.category = StringUtils.requireNotNullOrEmpty(category, "category cannot be null"); + this.type = StringUtils.requireNotNullOrEmpty(type, "type cannot be null"); this.key = XmppStringUtils.generateKey(category, type); this.name = name; this.lang = lang; @@ -493,9 +487,7 @@ public class DiscoverInfo extends IQ implements Cloneable { * @param variable the feature's variable. */ public Feature(String variable) { - if (variable == null) - throw new IllegalArgumentException("variable cannot be null"); - this.variable = variable; + this.variable = StringUtils.requireNotNullOrEmpty(variable, "variable cannot be null"); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java index 6ffbcd03b..f9839b9be 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java @@ -20,6 +20,7 @@ package org.jivesoftware.smackx.iqversion.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.util.StringUtils; /** * A Version IQ packet, which is used by XMPP clients to discover version information @@ -85,16 +86,9 @@ public class Version extends IQ { */ public Version(String name, String version, String os) { super(ELEMENT, NAMESPACE); - if (name == null) - { - throw new IllegalArgumentException("name must not be null"); - } - if (version == null) { - throw new IllegalArgumentException("version must not be null"); - } this.setType(IQ.Type.result); - this.name = name; - this.version = version; + this.name = StringUtils.requireNotNullOrEmpty(name, "name must not be null"); + this.version = StringUtils.requireNotNullOrEmpty(version, "version must not be null"); this.os = os; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index 5fdd0ff9f..ca2f9b167 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -274,9 +274,7 @@ public class MultiUserChat { private Presence enter(String nickname, String password, DiscussionHistory history, long timeout) throws NotConnectedException, NoResponseException, XMPPErrorException { - if (StringUtils.isNullOrEmpty(nickname)) { - throw new IllegalArgumentException("Nickname must not be null or blank."); - } + StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // We enter a room by sending a presence packet where the "to" // field is in the form "roomName@service/nickname" Presence joinPresence = new Presence(Presence.Type.available); @@ -844,9 +842,7 @@ public class MultiUserChat { * @throws NotConnectedException */ public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException { - if (StringUtils.isNullOrEmpty(nickname)) { - throw new IllegalArgumentException("Nickname must not be null or blank."); - } + StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // Check that we already have joined the room before attempting to change the // nickname. if (!joined) { @@ -881,9 +877,7 @@ public class MultiUserChat { * @throws NotConnectedException */ public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException { - if (StringUtils.isNullOrEmpty(nickname)) { - throw new IllegalArgumentException("Nickname must not be null or blank."); - } + StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // Check that we already have joined the room before attempting to change the // availability status. if (!joined) {