eclipse-paho / eclipse-paho/paho.mqtt.java

Create MqttAsyncClient() throw a ConcurrentModificationException

Open
#870 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
918
PR merge metrics
No merged PRs in 30d

Description

Bug exists Release Version 1.1.0 ( Master Branch) And I check the latest version 1.2.5 also exists。

When create MqttAsyncClient() throw a ConcurrentModificationException in API23. Caused by LoggerFactory.getLogger() -> ... -> ClassLoader.getResourceAsStream()...

MqttAsyncClient:
```
Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);
```

Class.getResourceAsStream is very slow on Android, should instead load from Android Resource Manager.

Also, Android **API 23** has a race condition with Class.getResourceAsStream that causes a ConcurrentModificationException

```
java.lang.ExceptionInInitializerError:
com.meitu.mqtt.manager.jni.MTMqttClient.create(MTMqttClient.java:122)
......
Caused by:
java.util.ConcurrentModificationException:
java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
java.util.HashMap$KeyIterator.next(HashMap.java:814)
java.util.jar.JarVerifier.readCertificates(JarVerifier.java:266)
java.util.jar.JarFile.getInputStream(JarFile.java:380)
libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
java.net.URL.openStream(URL.java:470)
java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:444)
java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:515)
java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:542)
java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:542)
java.util.ResourceBundle.getBundle(ResourceBundle.java:228)
java.util.ResourceBundle.getBundle(ResourceBundle.java:139)
org.eclipse.paho.client.mqttv3.logging.b.a(LoggerFactory.java:73)
org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:89)
com.meitu.mqtt.manager.jni.MTMqttClient.create(MTMqttClient.java:122)
com.meitu.mqtt.manager.jni.MTMqttClient.(MTMqttClient.java:95)
com.meitu.mqtt.manager.flow.a.a(IMConnector.kt:116)
com.meitu.mqtt.manager.flow.b$b.run(IMFlowExecutor.kt:79)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:159)
android.os.HandlerThread.run(HandlerThread.java:61)
```

the same problem:
https://github.com/firebase/firebase-android-sdk/issues/1601

Contributor guide

Open the contributing guide

Research direction

Start with LoggerFactory.java around line 73 and MqttAsyncClient.java around line 89, then reproduce creation on Android API 23 using the reported stack trace. Investigate the logger's ResourceBundle/ClassLoader lookup and the Android Resource Manager alternative mentioned in the issue. Done means creating MqttAsyncClient no longer triggers the ConcurrentModificationException on API 23.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.