Community
Participate
Working Groups
Hi, While testing mqtt-spy 0.4.0 beta with a snapshot version (1.0.3-20151116.050526-315) of the Paho Java client, I keep getting a null pointer: 2015-12-10 23:43:20,821 INFO [MqttAsyncConnectionRunnable ] - Connecting client ID [mqttspy] to server [[ws://broker.hivemq.com]]; options = ============== Connection options ============== CleanSession : true SocketFactory : null MqttVersion : 0 KeepAliveInterval : 60 ConTimeout : 30 UserName : null SSLProperties : null WillDestination : null ========================================== 2015-12-10 23:43:22,444 WARN [MqttConnectionResultHandler ] - Connecting to mqttspy@broker.hivemq.com failed MqttException (0) - java.lang.NullPointerException at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:633) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:97) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:66) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketNetworkModule.start(WebSocketNetworkModule.java:76) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:619) ... 1 more This is when I incorrectly configure the port. So I believe for ws:// it defaults to 1883 or 80, but the actual WebSockets broker is on 8000 in that situation. I tried that with test.mosquitto.org and when I specify the incorrect port of 80, I get the same: 2015-12-10 23:56:35,784 INFO [MqttAsyncConnectionRunnable ] - Connecting client ID [mqttspy] to server [[ws://test.mosquitto.org:80]]; options = ============== Connection options ============== CleanSession : true SocketFactory : null MqttVersion : 0 KeepAliveInterval : 60 ConTimeout : 30 UserName : null SSLProperties : null WillDestination : null ========================================== 2015-12-10 23:56:36,110 WARN [MqttConnectionResultHandler ] - Connecting to mqttspy@test.mosquitto.org:80 failed MqttException (0) - java.lang.NullPointerException at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:633) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:103) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:66) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketNetworkModule.start(WebSocketNetworkModule.java:76) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:619) ... 1 more Cheers, Kamil
The WebSocket client needs to fail safely when it does not get the response it expects. In this case it's opening a TCP port and sending an HTTP handshake. When it receives either nothing or data it does not expect it will fall over in this way. I'm adding a null check that will throw an IOException with a message along the lines of "Invalid response, server may not support websockets". I'll also change the default port behaviour when no port is provided. Although not everyone uses it, port 80 is the default port for WebSockets so I think that should be default if none is chosen as it's likely that most users would expect that.
New Gerrit change created: https://git.eclipse.org/r/62606
Thanks James! Is that fix going to be available as a 1.0.3-SNAPSHOT build at https://repo.eclipse.org/content/repositories/paho-snapshots/org/eclipse/paho/org.eclipse.paho.client.mqttv3/1.0.3-SNAPSHOT/?
Gerrit change https://git.eclipse.org/r/62606 was merged to [develop]. Commit: http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/commit/?id=d796504ab84ad1aff375f941f82ee71cc7370e6b
Migrated to GitHub Issue: https://github.com/eclipse/paho.mqtt.java/issues/14