Bug 484264 - Null pointer in Paho Java client WebSocket classes
Summary: Null pointer in Paho Java client WebSocket classes
Status: UNCONFIRMED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Paho (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: James Sutton CLA
QA Contact: Ian Craggs CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-11 17:39 EST by Kamil Baczkowicz CLA
Modified: 2016-02-05 11:16 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kamil Baczkowicz CLA 2015-12-11 17:39:12 EST
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
Comment 1 James Sutton CLA 2015-12-14 06:23:51 EST
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.
Comment 2 Eclipse Genie CLA 2015-12-14 06:30:19 EST
New Gerrit change created: https://git.eclipse.org/r/62606
Comment 3 Kamil Baczkowicz CLA 2015-12-17 17:03:47 EST
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/?
Comment 5 James Sutton CLA 2016-02-05 05:59:34 EST
Migrated to GitHub Issue: https://github.com/eclipse/paho.mqtt.java/issues/14