If an MXBean needs to reconstruct a type T, and T has a @ConstructorProperties constructor that has an array parameter (e.g. String[]) and a generic parameter (e.g. List<String>) then it is shown as unreconstructible:
Exception in thread "main" java.lang.IllegalArgumentException: java.io.InvalidObjectException: @ConstructorProperties gives property array of type class [Ljava.lang.String; for parameter of type java.lang.String[]: public MXBug$T(java.lang.String[],java.util.List)
at com.sun.jmx.mbeanserver.ConvertingMethod.checkCallToOpen(ConvertingMethod.java:96)
at com.sun.jmx.mbeanserver.MXBeanProxy$Visitor.visitAttribute(MXBeanProxy.java:53)
at com.sun.jmx.mbeanserver.MXBeanProxy$Visitor.visitAttribute(MXBeanProxy.java:48)
at com.sun.jmx.mbeanserver.MBeanAnalyzer.visit(MBeanAnalyzer.java:53)
at com.sun.jmx.mbeanserver.MXBeanProxy.<init>(MXBeanProxy.java:45)
at javax.management.MBeanServerInvocationHandler.findMXBeanProxy(MBeanServerInvocationHandler.java:318)
at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:247)
at $Proxy0.getT(Unknown Source)
at MXBug.main(MXBug.java:48)
Caused by: java.io.InvalidObjectException: @ConstructorProperties gives property array of type class [Ljava.lang.String; for parameter of type java.lang.String[]: public MXBug$T(java.lang.String[],java.util.List)
at com.sun.jmx.mbeanserver.OpenConverter$CompositeBuilderViaConstructor.applicable(OpenConverter.java:1178)
at com.sun.jmx.mbeanserver.OpenConverter$CompositeConverter.makeCompositeBuilder(OpenConverter.java:856)
at com.sun.jmx.mbeanserver.OpenConverter$CompositeConverter.checkReconstructible(OpenConverter.java:880)
at com.sun.jmx.mbeanserver.ConvertingMethod.checkCallToOpen(ConvertingMethod.java:94)
Here is the test program:
import java.beans.*;
import java.util.*;
import javax.management.*;
public class MXBug {
public interface TMXBean {
public T getT();
}
public static class TImpl implements TMXBean {
private final T t = new T(new String[] {"foo"}, Arrays.asList(new String[] {"bar"}));
public T getT() {
return t;
}
}
public static class T {
private final String[] array;
private final List<String> list;
@ConstructorProperties({"array", "list"})
public T(String[] array, List<String> list) {
this.array = array;
this.list = list;
}
public String[] getArray() {
return array;
}
public List<String> getList() {
return list;
}
@Override
public String toString() {
return Arrays.toString(array) + list;
}
}
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("d:k=v");
TImpl t = new TImpl();
mbs.registerMBean(t, name);
TMXBean proxy = JMX.newMXBeanProxy(mbs, name, TMXBean.class);
System.out.println(proxy.getT());
}
}