client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Illegal reflective access

Open GuiSim opened this issue 7 years ago • 9 comments

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?

GuiSim avatar Dec 04 '18 16:12 GuiSim

If you've got a proposal for how to deal with different JVM implementations without reflection, I'm all ears.

brian-brazil avatar Dec 04 '18 16:12 brian-brazil

@brian-brazil

I suspect that this is a very dumb suggestion but.. can't we use System.nanoTime() ?

GuiSim avatar Dec 04 '18 22:12 GuiSim

That's the current time, not how much CPU has been used.

brian-brazil avatar Dec 05 '18 08:12 brian-brazil

🤦‍♂️ Thanks, I knew I was missing something obvious.

GuiSim avatar Dec 05 '18 09:12 GuiSim

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.

pjfanning avatar Dec 06 '18 08:12 pjfanning

I'm not seeing those methods there.

brian-brazil avatar Dec 06 '18 08:12 brian-brazil

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.

pjfanning avatar Dec 06 '18 09:12 pjfanning

Yes, it's done this way to also work on the IBM JVM.

brian-brazil avatar Dec 06 '18 09:12 brian-brazil

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

jsoref avatar May 07 '20 19:05 jsoref