- 
                Notifications
    You must be signed in to change notification settings 
- Fork 41.6k
Description
Affects: Spring Boot 2.2.11 (but most likely the current version as well, the code is the same)
The ParentAwareNamingStrategy bean created by JmxAutoConfiguration changes the original order of key properties of the ObjectName unconditionally, as it decomposes the original name in getObjectName() and recreates it to add, if configured, "identity" and "context" fields, by using a Hashtable to temporarily store the key properties.
An object name defined with @ManagedResource like "ABC:type=something,name1=def,name2=ghi" with more than one property except "type" could therefore change to "ABC:type=something,name2=ghi,name1=def".
While two ObjectNames with the same key properties in different order are semantically equal and the canonical name stays the same, this change may not affect regular calls through the JMX API, but it at least affects JConsole, as JConsole relies on the property order to build the MBean hierarchy in the "MBeans" tab. Other tools that for whatever reason rely on the same order as defined in the code might be affected as well.
For the case above, a hierarchy ABC > def > ghi in JConsole might change to ABC > ghi > def, which at least affects things like documentation about where to find specific operations or attributes.
It's potentially not easily possible to keep the order intact if "identity" and "context" fields would need to be added, but it might be already helpful, if ParentAwareNamingStrategy would simply use the original name as-is, if these fields don't need to be added, similar to MBeanExporter#registerManagedResource(Object), that modifies the name only if changes are needed.