eclipse-paho / eclipse-paho/paho.mqtt.java
Exception on subscribe with mqttv5 MqttAsyncClient
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
- [x] Bug exists Release Version 1.2.5 ( Master Branch)
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
**The `1.2.6-SNAPSHOT` doesn't exist in the repository.**
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.
```java
final MqttProperties props = new MqttProperties();
props.setSubscriptionIdentifiers(Arrays.asList(new Integer[] { 0 }));
client.subscribe(new MqttSubscription(topic, DEFAULT_QOS), null, null, listener, props);
```
Contributor guide
Research direction
Read org.eclipse.paho.mqttv5.client.MqttAsyncClient.java at the subscribe overloads around lines 1202-1207 and 1272-1276, then reproduce the exception with the shorthand MqttSubscription call. Compare it with the documented MqttProperties workaround; done means the shorthand call no longer throws and its subscription-identifier behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100