-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
24
-
generic
-
generic
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 ----------
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 ----------