JDK-8264170 : ManagementFactory.getPlatformMBeanServer() does not return
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • Submitted: 2021-03-24
  • Updated: 2024-07-05
  • Resolved: 2024-07-05
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
NAME="Amazon Linux"
VERSION="2"

openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)



A DESCRIPTION OF THE PROBLEM :
We retrieve the MBean server  by making the below  call.

private static MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

After the above statement control never reached to the next line. 

Example: 
static {
    try {
      logger.info("static block started");
      MBeanServer mbs1 = ManagementFactory.getPlatformMBeanServer();
      logger.info("static block completed {}", mbs1);
    } catch (Exception e) {
      logger.error("static errror", e);
      e.printStackTrace();
    }
  }

Comment "static block completed" is never printed and neither any exception is thrown. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. In any test application in class define static member variable 
    private static MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

2. In a different method 
    register any mbean to the server 
    add log statement after the mbean register

3.  Invoke the method from any external class. 




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The MBean should be successfully registered and the log statement should be printed. 
ACTUAL -
The log statement is never registered. 

FREQUENCY : always



Comments
Requested the submitter download the latest version of JDK 8 from https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html and verify the results.
26-03-2021

Looking at this user provided stacktrace: Caused by: java.io.UncheckedIOException: java.nio.channels.ClosedByInterruptException at java.io.BufferedReader$1.hasNext(BufferedReader.java:574) at java.util.Iterator.forEachRemaining(Iterator.java:115) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) at jdk.internal.platform.cgroupv1.Metrics.initContainerSubSystems(Metrics.java:83) at jdk.internal.platform.cgroupv1.Metrics.<clinit>(Metrics.java:50) ... 22 common frames omitted It looks like they are running into this bug https://bugs.openjdk.java.net/browse/JDK-8255908 which seems to have been fixed and backported to JDK 8, recently.
26-03-2021

The observations on Windows 10 and Ubuntu: JDK 8: Passed, both before and after are printed. This incident might happened only on specific platforms.
26-03-2021

Additional information from the submitter: After adding catch for Throwable, I was able to get details on the error. java.lang.ExceptionInInitializerError: null at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at jdk.internal.platform.Metrics.systemMetrics(Metrics.java:59) at jdk.internal.platform.Container.metrics(Container.java:41) at sun.management.OperatingSystemImpl.<init>(OperatingSystemImpl.java:46) at sun.management.ManagementFactoryHelper.getOperatingSystemMXBean(ManagementFactoryHelper.java:106) at java.lang.management.PlatformComponent$7.getMXBeans(PlatformComponent.java:157) at java.lang.management.PlatformComponent.getMXBeans(PlatformComponent.java:377) at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:472) ...... at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.UncheckedIOException: java.nio.channels.ClosedByInterruptException at java.io.BufferedReader$1.hasNext(BufferedReader.java:574) at java.util.Iterator.forEachRemaining(Iterator.java:115) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) at jdk.internal.platform.cgroupv1.Metrics.initContainerSubSystems(Metrics.java:83) at jdk.internal.platform.cgroupv1.Metrics.<clinit>(Metrics.java:50) ... 22 common frames omitted Caused by: java.nio.channels.ClosedByInterruptException: null at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202) at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:164) at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65) at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109) at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) at java.io.BufferedReader.readLine(BufferedReader.java:389) at java.io.BufferedReader$1.hasNext(BufferedReader.java:571) ... 32 common frames omitted
26-03-2021

Provided the above suggestions to the submitter.
25-03-2021

Additional information from the submitter: Steps to run the application: 1. You can import the files in any IDE and run the class "App" 2. Expectation : In the console we should be able to see the lines before after Actual : Only "before" is printed and not after JAVA version: openjdk version "1.8.0_272" OpenJDK Runtime Environment (build 1.8.0_272-b10) OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode) OS : Linux Please can you check class "com.example.NotifyMonitor2" and advice if the below line of code is being used correctly. private static MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Kindly revert if more information is needed.
25-03-2021

To the reporter - It's possible that the invocation in that static block is leading to some "Error", which won't be caught by the catch(Exception) block. So the reporter could change their catch block to catch(Throwable) and see what gets caught.
25-03-2021