paho.mqtt.java icon indicating copy to clipboard operation
paho.mqtt.java copied to clipboard

FileLock may stop working in future versions of Java

Open jpwsutton opened this issue 7 years ago • 13 comments

Please fill out the form below before submitting, thank you!

  • [x] Bug exists Release Version 1.2.0 ( Master Branch)
  • [x] Bug exists in Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
  • [x] Bug exists in MQTTv5 Version (mqttv5-new Branch)

When compiling and testing against a Java 9 JVM, the following warning is logged:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.eclipse.paho.client.mqttv3.internal.FileLock (file:/Users/jsutton/ibm/paho/git/paho.mqtt.java/org.eclipse.paho.client.mqttv3/target/classes/) to method sun.nio.ch.FileLockImpl.release()
WARNING: Please consider reporting this to the maintainers of org.eclipse.paho.client.mqttv3.internal.FileLock
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

This is refering to the fact that FileLock.java uses reflection to check if the java.nio.channels.FileLock API is available, before then calling it.

The reason that this was written this way was to maintain support with JME MIDP which did not have the FileLock API available at the time. It would be worth doing some investigation to see whether this API is available in the latest versions of Java ME 8. If it is, then we can clean this class up considerably!

jpwsutton avatar Mar 27 '18 09:03 jpwsutton

Is JME MIDP or Java ME still a requirement?? Or maybe you could create a "legacy" branch ?

BrunoVernay avatar Oct 27 '18 20:10 BrunoVernay

+1, just migrated to Java 11 and I get the warnings

Khalil-Bouzekri avatar Dec 21 '18 13:12 Khalil-Bouzekri

+1 Same warning here, Java 11 on MacOS

evnix avatar Jan 23 '19 19:01 evnix

+1 same here Java 11 on ubuntu 18.04

fruwolt avatar Feb 29 '20 14:02 fruwolt

+1 same here as well Java 11 on ubuntu 18.04

panilov7 avatar Mar 29 '20 07:03 panilov7

@fruwolt @panilov7 I will look into this after next service release 1.2.3 (target release date 4/10/2020).

rdasgupt avatar Apr 06 '20 14:04 rdasgupt

@rdasgupt is this targeted for 1.2.5?

solidpulse avatar Apr 22 '20 17:04 solidpulse

@avierr We plan to add this in 1.2.5. The target release date is not worked out yet. We are planning to have a release with MQTTv5 support (which is pending for more than a year) before start planning for 1.2.5 (MQTTv3 service release).

rdasgupt avatar Apr 22 '20 20:04 rdasgupt

I'm afraid this hasn't been fixed in 1.2.5. Just tried with bumped up version of Maven dependency and the issue persists: WARNING: Illegal reflective access by org.eclipse.paho.client.mqttv3.internal.FileLock (.../1.2.5/1546cfc794449c39ad569853843a930104fdc297/org.eclipse.paho.client.mqttv3-1.2.5.jar) to method sun.nio.ch.FileLockImpl.release()

ocervinka avatar Oct 11 '20 14:10 ocervinka

I had the same problem and thus finally investigated the matter. The problem arises from the module system in Java 9 and higher where such access is discouraged (however still permitted). Until this problem is fixed in paho.mqtt.java you can explicitely allow such accesses by using a cmd line argument when running the java program. You just have to add the following option:

--add-opens=java.base/sun.nio.ch=ALL-UNNAMED

This does not only cause the message go away but it also allows explitly the desired access. (See also https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-7BB28E4D-99B3-4078-BDC4-FC24180CE82B)

rz259 avatar Apr 07 '21 07:04 rz259

same here, on MQTT V5 Jdk 13.01 on win10 pro x64

KeithLaiKB avatar Apr 28 '21 06:04 KeithLaiKB

Still happening with org.eclipse.paho.client.mqttv3 v 1.2.5 and JDK 9: java version "9.0.1" Java(TM) SE Runtime Environment (build 9.0.1+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

jeff-bonevich avatar May 16 '21 14:05 jeff-bonevich

Still same problem. Is there any update on this issue ?

yilmaznaslan avatar Nov 23 '21 17:11 yilmaznaslan