Skip to content

Exception on subscribe with mqttv5 MqttAsyncClient #826

@escoand

Description

@escoand
  • 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions