Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to make public long com.sun.management.internal.OperatingSystemImpl.getOpenFileDescriptorCount() [closed]

I am getting the below error in server log in Java 11. Is there any solution for it?

[2019-05-02 18:06:18 IST] [] ERROR com.codahale.metrics.ScheduledReporter [SID= UID= BGCD=] - Exception thrown from Slf4jReporter#report. Exception was suppressed.
java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getOpenFileDescriptorCount() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @489448ac
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:198)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:192)
    at deployment.myPage.war//com.codahale.metrics.jvm.FileDescriptorRatioGauge.invoke(FileDescriptorRatioGauge.java:48)
    at deployment.myPage.war//com.codahale.metrics.jvm.FileDescriptorRatioGauge.getRatio(FileDescriptorRatioGauge.java:35)
    at deployment.myPage.war//com.codahale.metrics.RatioGauge.getValue(RatioGauge.java:64)
    at deployment.myPage.war//com.codahale.metrics.RatioGauge.getValue(RatioGauge.java:11)
    at deployment.myPage.war//com.codahale.metrics.DerivativeGauge.getValue(DerivativeGauge.java:23)
    at deployment.myPage.war//com.codahale.metrics.Slf4jReporter.logGauge(Slf4jReporter.java:306)
    at deployment.myPage.war//com.codahale.metrics.Slf4jReporter.report(Slf4jReporter.java:220)
    at deployment.myPage.war//com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:243)
    at deployment.myPage.war//com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:182)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
like image 739
SKR Avatar asked May 02 '19 12:05

SKR


2 Answers

One of the dependencies of your project is trying to access a jvm api which was moved to an internal java module, and is no longer exposed.

Running the application with following flag should solve the problem:

--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
like image 126
senjin.hajrulahovic Avatar answered Nov 17 '22 01:11

senjin.hajrulahovic


This issue was fixed in Dropwizard metrics 4.0.0, see https://github.com/dropwizard/metrics/pull/1236

So you need to raise the version of your dependency. In case you are using Spring Boot, you can raise the parent version to 2.1.

If raising the version is not an option, follow @senjin.hajrulahovic's answer to open com.sun.management.internal module.

like image 25
helospark Avatar answered Nov 17 '22 03:11

helospark