eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.08k stars 879 forks source link

Exception on subscribe with mqttv5 MqttAsyncClient #826

Open escoand opened 3 years ago

escoand commented 3 years ago

When subscribing to a topic with the call client.subscribe(new MqttSubscription(topic, DEFAULT_QOS), listener); I get the following exception:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[?:1.8.0_74]
    at java.util.ArrayList.get(ArrayList.java:429) ~[?:1.8.0_74]
    at org.eclipse.paho.mqttv5.client.MqttAsyncClient.subscribe(MqttAsyncClient.java:1276) ~[org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at org.eclipse.paho.mqttv5.client.MqttAsyncClient.subscribe(MqttAsyncClient.java:1205) ~[org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at de.vwgis.visu.backend.MessageService._subscribe(MessageService.java:183) ~[classes/:?]
    at de.vwgis.visu.backend.MessageService.access$4(MessageService.java:180) ~[classes/:?]
    at java.util.HashMap.forEach(HashMap.java:1280) [?:1.8.0_74]
    at de.vwgis.visu.backend.MessageService$CustomMqttCallback.connectComplete(MessageService.java:197) [classes/:?]
    at org.eclipse.paho.mqttv5.client.internal.ConnectActionListener.onSuccess(ConnectActionListener.java:175) [org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at org.eclipse.paho.mqttv5.client.internal.CommsCallback.fireActionEvent(CommsCallback.java:358) [org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at org.eclipse.paho.mqttv5.client.internal.CommsCallback.handleActionComplete(CommsCallback.java:285) [org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at org.eclipse.paho.mqttv5.client.internal.CommsCallback.run(CommsCallback.java:209) [org.eclipse.paho.mqttv5.client-1.2.5.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_74]

The reason is this https://github.com/eclipse/paho.mqtt.java/blob/6f35dcb785597a6fd49091efe2dba47513939420/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttAsyncClient.java#L1202-L1207 in connection with https://github.com/eclipse/paho.mqtt.java/blob/6f35dcb785597a6fd49091efe2dba47513939420/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttAsyncClient.java#L1272-L1276

Why and how to set a subId when there is this shorthand method?

Workaround is simple by creating the MqttProperties self.

final MqttProperties props = new MqttProperties();
props.setSubscriptionIdentifiers(Arrays.asList(new Integer[] { 0 }));
client.subscribe(new MqttSubscription(topic, DEFAULT_QOS), null, null, listener, props);
jameskleeh commented 3 years ago

@rdasgupt If I submit a PR for this fix today can I be sure that it will be reviewed and, if acceptable, merged for the next release?

EAGrahamJr commented 11 months ago

This still occurs with 1.2.5 and still requires the workaround.

yuremboo commented 9 months ago

Do you happen to have any updates on this?

Perondas commented 8 months ago

How and why is this still open?

Stephan23 commented 2 weeks ago

I have just encountered the same problem. Is still an issue version 1.2.5

goddi commented 2 weeks ago

I can confirm that the problem is still present in version 1.2.5