JDK-6602326 : No InstanceAlreadyExistsException for the second registration of an MXBean object under dif. name
  • 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-07
  • Updated: 2017-05-16
  • Resolved: 2007-10-26
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 b06Fixed 7Fixed
Related Reports
Relates :  
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 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.
11-09-2007

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.
10-09-2007