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

MBeanServer.setAttribute not docs RuntimeMBeanException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 24
    • core-svc

      A DESCRIPTION OF THE PROBLEM :
      When you set an invalid attribute which could trigger an exception for an object, setAttribute will throw a RuntimeMBeanException wrapping that exception. But the documentation does not mention this.


      ---------- BEGIN SOURCE ----------

      import java.lang.management.*;
      import javax.management.*;
      import java.util.*;
      import static java.lang.management.ManagementFactory.*;

      public class MXBeanException {
          public static void main(String[] argv) throws Exception {
              List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
              MemoryPoolMXBean pool = null;
              for (MemoryPoolMXBean p : pools) {
                  if (!p.isUsageThresholdSupported()) {
                      pool = p;
                      break;
                  }
              }

              // Get expected exception type from direct call
              Class<? extends Throwable> directExceptionClass = null;
              try {
                  pool.setUsageThreshold(1000);
              } catch (UnsupportedOperationException e) {
                  System.out.println("Can't set usage threshold for memory pool: " + pool.getName());
                  directExceptionClass = e.getClass();
              }

              // Check exception through MBeanServer
              MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
              ObjectName on = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE +
                                             ",name=" + pool.getName());
              Attribute att = new Attribute("UsageThreshold", 1000);
              try {
                  mbs.setAttribute(on, att);
              } catch (MBeanException | RuntimeOperationsException | InvalidAttributeValueException | AttributeNotFoundException |
                       InstanceNotFoundException e) {
                  //
              }

          }


      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: