United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6600709 MXBeans: SortedMap<K,V> fails when V is an array of primitives
6600709 : MXBeans: SortedMap fails when V is an array of primitives

Details
Type:
Bug
Submit Date:
2007-09-04
Status:
Resolved
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2007-11-06
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u10

Related Reports
Backport:
Relates:

Sub Tasks

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.
                                     
2007-10-23
WORK AROUND

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



Hardware and Software, Engineered to Work Together