paho.mqtt.java
paho.mqtt.java copied to clipboard
NetworkModuleService.applyRFC3986AuthorityPatch() fails with Java 17 and URL with non-alphanumeric chars
Description
I try to use paho MQTTv3 version 1.2.5 together with Java 17 (debian11, openjdk-17-jre-headless). I get the following exception when calling the connect method of MqttAsyncClient. I use a broker URL with underlines in the host name.
I think this issue is related to https://github.com/eclipse/paho.mqtt.java/issues/507
- [x] Bug exists Release Version 1.2.5 ( Master Branch) not checked with MQTTv5 and 1.2.6-SNAPSHOT
java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.lang.String java.net.URI.userInfo accessible: module java.base does not "opens java.net" to unnamed module @50c87b21
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
at org.eclipse.paho.client.mqttv3.internal.NetworkModuleService.setURIField(NetworkModuleService.java:153)
at org.eclipse.paho.client.mqttv3.internal.NetworkModuleService.applyRFC3986AuthorityPatch(NetworkModuleService.java:137)
at org.eclipse.paho.client.mqttv3.internal.NetworkModuleService.createInstance(NetworkModuleService.java:96)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.createNetworkModule(MqttAsyncClient.java:663)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.createNetworkModules(MqttAsyncClient.java:642)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:748)
...
Find the method here If the method does not return directly it fails.
Workaround
Add the following JVM parameter to avoid the exception:
--add-opens=java.base/java.net=ALL-UNNAMED