diff --git a/src/main/java/io/vertx/mqtt/MqttClientOptions.java b/src/main/java/io/vertx/mqtt/MqttClientOptions.java index f3ebe3ed..a6a68a2f 100644 --- a/src/main/java/io/vertx/mqtt/MqttClientOptions.java +++ b/src/main/java/io/vertx/mqtt/MqttClientOptions.java @@ -20,7 +20,6 @@ import io.vertx.codegen.annotations.GenIgnore; import io.vertx.codegen.json.annotations.JsonGen; import io.vertx.core.buffer.Buffer; -import io.vertx.core.impl.Arguments; import io.vertx.core.json.JsonObject; import io.vertx.core.net.*; @@ -456,8 +455,9 @@ public int getMaxMessageSize() { @Override public MqttClientOptions setReceiveBufferSize(int receiveBufferSize) { if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) { - Arguments.require(receiveBufferSize >= this.maxMessageSize, - "Receiver buffer size can't be lower than max message size"); + if (receiveBufferSize < this.maxMessageSize) { + throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size"); + } } super.setReceiveBufferSize(receiveBufferSize); return this; @@ -470,10 +470,13 @@ public MqttClientOptions setReceiveBufferSize(int receiveBufferSize) { * @return MQTT client options instance */ public MqttClientOptions setMaxMessageSize(int maxMessageSize) { - Arguments.require(maxMessageSize > 0 || maxMessageSize == DEFAULT_MAX_MESSAGE_SIZE, "maxMessageSize must be > 0"); + if (maxMessageSize <= 0 && maxMessageSize != DEFAULT_MAX_MESSAGE_SIZE) { + throw new IllegalArgumentException( "maxMessageSize must be > 0"); + } if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { - Arguments.require(this.getReceiveBufferSize() >= maxMessageSize, - "Receiver buffer size can't be lower than max message size"); + if (this.getReceiveBufferSize() < maxMessageSize) { + throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size"); + } } this.maxMessageSize = maxMessageSize; return this; diff --git a/src/main/java/io/vertx/mqtt/MqttServerOptions.java b/src/main/java/io/vertx/mqtt/MqttServerOptions.java index c7d478e4..f7860bfe 100644 --- a/src/main/java/io/vertx/mqtt/MqttServerOptions.java +++ b/src/main/java/io/vertx/mqtt/MqttServerOptions.java @@ -20,7 +20,6 @@ import io.vertx.codegen.json.annotations.JsonGen; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.ClientAuth; -import io.vertx.core.impl.Arguments; import io.vertx.core.json.JsonObject; import io.vertx.core.net.JksOptions; import io.vertx.core.net.KeyCertOptions; @@ -115,8 +114,9 @@ public MqttServerOptions(JsonObject json) { MqttServerOptionsConverter.fromJson(json, this); if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { - Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize, - "Receiver buffer size can't be lower than max message size"); + if (this.getReceiveBufferSize() < this.maxMessageSize) { + throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size"); + } } } @@ -204,8 +204,9 @@ public MqttServerOptions addCrlValue(Buffer crlValue) throws NullPointerExceptio @Override public MqttServerOptions setReceiveBufferSize(int receiveBufferSize) { if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) { - Arguments.require(receiveBufferSize >= this.maxMessageSize, - "Receiver buffer size can't be lower than max message size"); + if (receiveBufferSize < this.maxMessageSize) { + throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size"); + } } super.setReceiveBufferSize(receiveBufferSize); return this; @@ -224,10 +225,13 @@ public MqttServerOptions setSni(boolean sni) { * @return MQTT server options instance */ public MqttServerOptions setMaxMessageSize(int maxMessageSize) { - Arguments.require(maxMessageSize > 0, "maxMessageSize must be > 0"); - if (this.getReceiveBufferSize() > 0) { - Arguments.require(this.getReceiveBufferSize() >= maxMessageSize, - "Receiver buffer size can't be lower than max message size"); + if (maxMessageSize <= 0 && maxMessageSize != DEFAULT_MAX_MESSAGE_SIZE) { + throw new IllegalArgumentException( "maxMessageSize must be > 0"); + } + if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { + if (this.getReceiveBufferSize() < maxMessageSize) { + throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size"); + } } this.maxMessageSize = maxMessageSize; return this; @@ -272,7 +276,9 @@ public int getMaxClientIdLength() { * @return MQTT server options instance */ public MqttServerOptions setMaxClientIdLength(int maxClientIdLength) { - Arguments.require(maxClientIdLength > 0, "maxClientIdLength must be > 0"); + if (maxClientIdLength <= 0) { + throw new IllegalArgumentException("maxClientIdLength must be > 0"); + } this.maxClientIdLength = maxClientIdLength; return this; } @@ -362,7 +368,9 @@ public int getWebSocketMaxFrameSize() { * @param webSocketMaxFrameSize the new frame size */ public void setWebSocketMaxFrameSize(int webSocketMaxFrameSize) { - Arguments.require(webSocketMaxFrameSize > 0, "WebSocket max frame size must be > 0"); + if (webSocketMaxFrameSize <= 0) { + throw new IllegalArgumentException("WebSocket max frame size must be > 0"); + } this.webSocketMaxFrameSize = webSocketMaxFrameSize; } diff --git a/src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java b/src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java index d540696e..61ab1bb9 100644 --- a/src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java +++ b/src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java @@ -410,7 +410,7 @@ public MqttEndpointImpl accept(boolean sessionPresent) { public MqttEndpointImpl accept(boolean sessionPresent, MqttProperties properties) { synchronized (conn) { if (this.isConnected) { - throw new IllegalStateException("Connection already accepted"); + throw new IllegalArgumentException("Connection already accepted"); } return this.connack(MqttConnectReturnCode.CONNECTION_ACCEPTED, sessionPresent, properties); @@ -889,7 +889,7 @@ private Future write(io.netty.handler.codec.mqtt.MqttMessage mqttMessage) private void checkClosed() { if (this.isClosed) { - throw new IllegalStateException("MQTT endpoint is closed"); + throw new IllegalArgumentException("MQTT endpoint is closed"); } } @@ -899,7 +899,7 @@ private void checkClosed() { private void checkConnected() { if (!this.isConnected) { - throw new IllegalStateException("Connection not accepted yet"); + throw new IllegalArgumentException("Connection not accepted yet"); } } diff --git a/src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java b/src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java index 0b048d8a..bfc89c6b 100644 --- a/src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java +++ b/src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java @@ -457,7 +457,7 @@ private boolean checkConnected() { return true; } else { so.close(); - throw new IllegalStateException("Received an MQTT packet from a not connected client (CONNECT not sent yet)"); + throw new IllegalArgumentException("Received an MQTT packet from a not connected client (CONNECT not sent yet)"); } } } diff --git a/src/main/java/io/vertx/mqtt/messages/impl/MqttPublishMessageImpl.java b/src/main/java/io/vertx/mqtt/messages/impl/MqttPublishMessageImpl.java index bb79f413..d3f6e9b0 100644 --- a/src/main/java/io/vertx/mqtt/messages/impl/MqttPublishMessageImpl.java +++ b/src/main/java/io/vertx/mqtt/messages/impl/MqttPublishMessageImpl.java @@ -96,9 +96,9 @@ public void setAckCallback(MqttPubAckCallback ackCallback) { public void ack() { if (this.qosLevel == MqttQoS.AT_LEAST_ONCE || this.qosLevel == MqttQoS.EXACTLY_ONCE) { if (ackCallback == null) { - throw new IllegalStateException("Callback not present. Check that Auto Ack is disabled."); + throw new IllegalArgumentException("Callback not present. Check that Auto Ack is disabled."); } else if (isAcked) { - throw new IllegalStateException("Ack of message " + messageId + " altready sent."); + throw new IllegalArgumentException("Ack of message " + messageId + " altready sent."); } else { isAcked = true; ackCallback.ack();