JDK-6600709 : MXBeans: SortedMap fails when V is an array of primitives
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-09-04
  • Updated: 2012-03-22
  • Resolved: 2007-11-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10 b07Fixed 7Fixed
Related Reports
Relates :  
Description
The MXBean spec says:

-------------------------------8<---------------------------------
Mappings for maps (Map<K,V> etc)
...

A SortedMap<K,V> is mapped in the same way, but it is only convertible if K is a class or interface that implements Comparable. Thus, a *SortedMap<String,int[]>* is convertible, but a SortedMap<int[],String> is not.
-------------------------------8<---------------------------------


In fact, an attempt to create an MXBean with the attribute of type SortedMap<String,int[]> leads to the following exception:
-------------------------------8<---------------------------------
javax.management.NotCompliantMBeanException: proto.negative_tests.Fwrk$ReconstructibleClass02MXBean: Method proto.negative_tests.Fwrk$ReconstructibleClass02MXBean.getSortedMap has parameter or return type that cannot be translated into an open type
        at com.sun.jmx.mbeanserver.Introspector.throwException(Introspector.java:412)
        at com.sun.jmx.mbeanserver.MBeanAnalyzer.<init>(MBeanAnalyzer.java:98)
        at com.sun.jmx.mbeanserver.MBeanAnalyzer.analyzer(MBeanAnalyzer.java:84)
        at com.sun.jmx.mbeanserver.MXBeanIntrospector.getAnalyzer(MXBeanIntrospector.java:53)
        at com.sun.jmx.mbeanserver.MBeanIntrospector.getPerInterface(MBeanIntrospector.java:163)
        at com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:147)
        at com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:48)
        at com.sun.jmx.mbeanserver.Introspector.makeDynamicMBean(Introspector.java:184)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:915)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:294)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:199)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:286)
        at proto.negative_tests.Fwrk.m1(Fwrk.java:34)
        at proto.negative_tests.Fwrk.main(Fwrk.java:25)
Caused by: java.lang.IllegalArgumentException: Method proto.negative_tests.Fwrk$ReconstructibleClass02MXBean.getSortedMap has parameter or return type that cannot be translated into an open type
        at com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:32)
        at com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:63)
        at com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:33)
        at com.sun.jmx.mbeanserver.MBeanAnalyzer.initMaps(MBeanAnalyzer.java:115)
        at com.sun.jmx.mbeanserver.MBeanAnalyzer.<init>(MBeanAnalyzer.java:96)
        ... 12 more
Caused by: javax.management.openmbean.OpenDataException: Cannot obtain array class
        at com.sun.jmx.mbeanserver.OpenConverter.openDataException(OpenConverter.java:1370)
        at com.sun.jmx.mbeanserver.OpenConverter.makeArrayOrCollectionConverter(OpenConverter.java:321)
        at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:274)
        at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:256)
        at com.sun.jmx.mbeanserver.OpenConverter.makeTabularConverter(OpenConverter.java:352)
        at com.sun.jmx.mbeanserver.OpenConverter.makeParameterizedConverter(OpenConverter.java:394)
        at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:288)
        at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:256)
        at com.sun.jmx.mbeanserver.ConvertingMethod.<init>(ConvertingMethod.java:184)
        at com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:27)
        ... 16 more
Caused by: java.lang.ClassNotFoundException: [Lint;
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at com.sun.jmx.mbeanserver.OpenConverter.makeArrayOrCollectionConverter(OpenConverter.java:319)
        ... 24 more
-------------------------------8<---------------------------------

The test class attached.

Comments
EVALUATION It appears that the problem arises because of bug 5041784. When you look at the int[] that appears inside SortedMap<String, int[]>, you get a GenericArrayType instead of int[].class. We have a converter recorded for int[].class but not for this GenericArrayType. In the MXBean code, we can work around this problem until 5041784 is fixed. The workaround will have no effect after that fix, so we can remove it at our leisure.
23-10-2007

WORK AROUND It is generally not recommended to mix arrays and generics. Instead of SortedMap<String, int[]>, you can use SortedMap<String, List<Integer>>.
05-09-2007

EVALUATION OpenConverter.makeArrayOrCollectionConverter has this comment: * We never see one-dimensional * primitive arrays (e.g. int[]) here because they use the identity * converter and are registered as such in the static initializer. But unfortunately that is false in the case in question.
05-09-2007