Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8054434

ClassCastException on HotSpotDiagnosticMXBean.getDiagnosticOptions()

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_25"
      Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
      Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If i use getDiagnoseOptions() of a HotSpotDiagnosticMXBean instance, a classcast exception occures.


      REGRESSION. Last worked in version 6u25

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      get HotSpotDiagnosticsMXBean instance and try to get diagnostic options

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      any output like 'options: [<vmoptions>]'
      ACTUAL -
      Exception in thread "main" java.lang.ClassCastException: [Ljavax.management.openmbean.CompositeData; cannot be cast to java.util.List
      at $Proxy0.getDiagnosticOptions(Unknown Source)
      at Dummy.main(Dummy.java:17)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassCastException: [Ljavax.management.openmbean.CompositeData; cannot be cast to java.util.List
      at $Proxy0.getDiagnosticOptions(Unknown Source)
      at Dummy.main(Dummy.java:17)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.management.ManagementFactory;
      import java.util.List;

      import javax.management.MBeanServerInvocationHandler;
      import javax.management.ObjectName;

      import com.sun.management.HotSpotDiagnosticMXBean;
      import com.sun.management.VMOption;

      public class Dummy2 {
      public static void main(String[] args) throws Exception {
      ObjectName hsdObjectName = new ObjectName(
      "com.sun.management:type=HotSpotDiagnostic");
      HotSpotDiagnosticMXBean hsdMXBean = MBeanServerInvocationHandler
      .newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
      hsdObjectName, HotSpotDiagnosticMXBean.class, false);
      List<VMOption> options = hsdMXBean.getDiagnosticOptions();
      System.out.printf("options: %1$s\n", options);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Get attribute directly from MBeanServer:

      import java.lang.management.ManagementFactory;
      import java.util.Arrays;

      import javax.management.MBeanServer;
      import javax.management.ObjectName;
      import javax.management.openmbean.CompositeData;

      public class Dummy {
      public static void main(String[] args) throws Exception {

      ObjectName hsdObjectName = new ObjectName(
      "com.sun.management:type=HotSpotDiagnostic");
      MBeanServer F_server = ManagementFactory.getPlatformMBeanServer();
      CompositeData[] attribute = (CompositeData[]) F_server.getAttribute(
      hsdObjectName, "DiagnosticOptions");
      System.out.printf("Options: %1$s\n", Arrays.toString(attribute));
      }
      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: