United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6602326 No InstanceAlreadyExistsException for the second registration of an MXBean object under dif. name
JDK-6602326 : No InstanceAlreadyExistsException for the second registration of an MXBean object under dif. name

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

Related Reports
Backport:
Relates:

Sub Tasks

Description
The MXBean spec says:

---------------------------------------8<----------------------------------------
If the same MXBean were registered under two different ObjectNames, a reference to that MXBean from another MXBean would be ambiguous. Therefore, if an MXBean object is already registered in an MBean Server and an attempt is made to register it in the same MBean Server under another name, the result is an InstanceAlreadyExistsException. 
---------------------------------------8<----------------------------------------

However, the following code does not throw the InstanceAlreadyExistsException:
---------------------------------------8<----------------------------------------
            ObjectName objectName1 = new ObjectName("test:index=1");
            ObjectName objectName2 = new ObjectName("test:index=2");
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();
            MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();
            
            mbs.registerMBean(mxBeanObject, objectName1);
            
            mbs.registerMBean(mxBeanObject, objectName2);
            System.out.println("InstanceAlreadyExistsException is not thrown.");
---------------------------------------8<----------------------------------------
(the sample test class attached)

                                    

Comments
EVALUATION

The existing logic to check for this falsely assumes that if the same object is registered twice then it will get the same MXBeanSupport wrapper in both cases.
                                     
2007-09-10
EVALUATION

There is a non-negligible risk that existing code depends on this behaviour.  Even though registering an MBean under two different names is strongly discouraged for the reasons explained at <http://weblogs.java.net/blog/emcmanus/archive/2005/07/can_you_registe.html>, we can't exclude the possibility that some existing deployments do it with MXBeans.  Therefore I suggest we introduce a property jmx.mxbean.multiname which restores the existing buggy behaviour.  If your app does depend on the bug, then you can run it with -Djmx.mxbean.multiname once the bug has been fixed, and it will continue to behave as before.
                                     
2007-09-11



Hardware and Software, Engineered to Work Together