Illegal reflective access
Hello!
We recently upgraded to Java 11 (from Java 8) and we've hit the following WARNINGs in our services that use Prometheus:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.prometheus.client.hotspot.StandardExports (jar:redacted!/BOOT-INF/lib/simpleclient_hotspot-0.0.23.jar!/) to method com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl.getProcessCpuTime()
WARNING: Please consider reporting this to the maintainers of io.prometheus.client.hotspot.StandardExports
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
This appears to be caused by this line: https://github.com/prometheus/client_java/blob/11408239035f02a125fe3c860f05fcd0be1e7873/simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/StandardExports.java#L64
I'd be curious to hear if this is something other users of the Prometheus Client library have hit. I'm unsure how to work around this, any suggestions?
If you've got a proposal for how to deal with different JVM implementations without reflection, I'm all ears.
@brian-brazil
I suspect that this is a very dumb suggestion but.. can't we use System.nanoTime() ?
That's the current time, not how much CPU has been used.
🤦♂️ Thanks, I knew I was missing something obvious.
One option would be to drop Java 6 support. https://docs.oracle.com/javase/7/docs/api/java/lang/management/OperatingSystemMXBean.html has the required methods in Java 7 and therefore could be called without reflection.
I'm not seeing those methods there.
Apologies - I got confused by https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html (same class name, different package) but this is a com.sun.management interface so it seems best to use reflection.
Yes, it's done this way to also work on the IBM JVM.
Is https://github.com/hazelcast/hazelcast/pull/14798 relevant?
Specifically createRequirement.
Afaict, they seem to avoid using reflection to get there, mostly a Properties.getProperty