Content Description:
Problem Description
When using the Eclipse Paho MQTT v5 client library (version 1.2.5), calling the MqttClient.subscribe() method results in a java.lang.StackOverflowError exception. The error stack trace shows that the method repeatedly calls itself at line 525 in the org.eclipse.paho.mqttv5.client.MqttClient class, forming an infinite recursion.
Error Stack Trace
java.lang.StackOverflowError at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) ... (hundreds of repeated calls to the same method)
Code Analysis
An obvious infinite recursion issue was found in the MqttClient class:
public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException {
return this.subscribe(topicFilters, qos, messageListeners); // Calls itself, causing infinite recursion
}
Environment Information
- MQTT Client Library: Eclipse Paho MQTT v5
- Version: 1.2.5
- Dependency Configuration:
org.eclipse.paho
org.eclipse.paho.mqttv5.client
1.2.5
compile
true
Reproduction Steps
- Create an MqttClient instance and establish a connection
- Call the subscribe method to subscribe to any topic
- Observe the StackOverflowError exception
Expected Behavior
The subscribe method should execute the subscription operation normally without falling into infinite recursion and causing a stack overflow.
Additional Information
- The issue occurs in both the MQTT client initialization and reconnection logic
- No subscription calls are made within the messageArrived method, ruling out recursion caused by custom code
- The project also depends on MQTT v3 client library (same version), but the issue appears in v5 client calls
Content Description:
Problem Description
When using the Eclipse Paho MQTT v5 client library (version 1.2.5), calling the
MqttClient.subscribe()method results in ajava.lang.StackOverflowErrorexception. The error stack trace shows that the method repeatedly calls itself at line 525 in theorg.eclipse.paho.mqttv5.client.MqttClientclass, forming an infinite recursion.Error Stack Trace
java.lang.StackOverflowError at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) ... (hundreds of repeated calls to the same method)
Code Analysis
An obvious infinite recursion issue was found in the MqttClient class:
public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException {
return this.subscribe(topicFilters, qos, messageListeners); // Calls itself, causing infinite recursion
}
Environment Information
- MQTT Client Library: Eclipse Paho MQTT v5
- Version: 1.2.5
- Dependency Configuration:
org.eclipse.paho org.eclipse.paho.mqttv5.client 1.2.5 compile trueReproduction Steps
Expected Behavior
The subscribe method should execute the subscription operation normally without falling into infinite recursion and causing a stack overflow.
Additional Information