diff --git a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java index 9d59daad3..126a50ed7 100644 --- a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java +++ b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java @@ -30,6 +30,8 @@ */ public class MqttClientConnection extends CrtResource { + private static final int MAX_PORT = 65535; + private MqttConnectionConfig config; private AsyncCallback connectAck; @@ -95,7 +97,7 @@ public MqttClientConnection(MqttConnectionConfig config) throws MqttException { if (config.getEndpoint() == null) { throw new MqttException("endpoint must not be null"); } - if (config.getPort() <= 0 || config.getPort() > 65535) { + if (config.getPort() <= 0 || config.getPort() > MAX_PORT) { throw new MqttException("port must be a positive integer between 1 and 65535"); } @@ -136,7 +138,7 @@ public MqttClientConnection(Mqtt5Client mqtt5client, MqttClientConnectionEvents if (config.getEndpoint() == null) { throw new MqttException("endpoint must not be null"); } - if (config.getPort() <= 0 || config.getPort() > 65535) { + if (config.getPort() <= 0 || config.getPort() > MAX_PORT) { throw new MqttException("port must be a positive integer between 1 and 65535"); } @@ -310,9 +312,9 @@ public CompletableFuture connect() throws MqttException { // Just clamp the pingTimeout, no point in throwing short pingTimeout = (short) Math.max(0, Math.min(config.getPingTimeoutMs(), Short.MAX_VALUE)); - short port = (short) config.getPort(); - if (port > Short.MAX_VALUE || port <= 0) { - throw new MqttException("Port must be betweeen 0 and " + Short.MAX_VALUE); + int port = config.getPort(); + if (port > MAX_PORT || port <= 0) { + throw new MqttException("Port must be betweeen 0 and 65535"); } CompletableFuture future = new CompletableFuture<>(); connectAck = AsyncCallback.wrapFuture(future, null); @@ -487,7 +489,7 @@ private static native long mqttClientConnectionNewFrom5Client(long client, MqttC private static native void mqttClientConnectionDestroy(long connection); - private static native void mqttClientConnectionConnect(long connection, String endpoint, short port, + private static native void mqttClientConnectionConnect(long connection, String endpoint, int port, long socketOptions, long tlsContext, String clientId, boolean cleanSession, int keepAliveMs, short pingTimeoutMs, int protocolOperationTimeoutMs) throws CrtRuntimeException; diff --git a/src/native/mqtt_connection.c b/src/native/mqtt_connection.c index 445db90e3..10a03bff6 100644 --- a/src/native/mqtt_connection.c +++ b/src/native/mqtt_connection.c @@ -574,7 +574,7 @@ void JNICALL Java_software_amazon_awssdk_crt_mqtt_MqttClientConnection_mqttClien jclass jni_class, jlong jni_connection, jstring jni_endpoint, - jshort jni_port, + jint jni_port, jlong jni_socket_options, jlong jni_tls_ctx, jstring jni_client_id, @@ -594,7 +594,7 @@ void JNICALL Java_software_amazon_awssdk_crt_mqtt_MqttClientConnection_mqttClien struct aws_byte_cursor client_id; AWS_ZERO_STRUCT(client_id); struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jstring_acquire(env, jni_endpoint); - uint16_t port = jni_port; + uint16_t port = (uint16_t)jni_port; if (!port) { aws_jni_throw_runtime_exception( env,