Closed
Description
Piotr Findeisen opened SPR-11002 and commented
MBeanExporter
, MBeanRegistrationSupport
lack any for of synchronization and there are many things that can happen if they are used from 2+ threads.
##### steps
1. `REGISTRATION_REPLACE_EXISTING` is `true`
1. thread 1: register called with name `nameA`
1. thread 1: registration completes
1. thread 2: register called with name `nameA`
1. thread 2: gets `InstanceAlreadyExistsException`
1. thread 1: unregisters `nameA`
1. thread 2: handles `InstanceAlreadyExistsException` by calling `this.server.unregisterMBean(objectName);`
##### expected
* `registrationBehavior == REGISTRATION_REPLACE_EXISTING` should prevent any `InstanceAlreadyExistsException` from being propagated to the callers
##### observed
* indeed, `InstanceAlreadyExistsException` is not propagated
* but `InstanceNotFoundException` is raised instead
##### steps
1. thread 1: calls register `nameA`
1. thread 1: registration completes
1. thread 1: calls unregister `nameA`
1. thread 1: `nameA` is removed from the server but not yet from `registeredBeans`
1. thread 2: calls register `nameA`
1. thread 2: registration completes; `nameA` is not added to `registeredBeans` because it is already there
1. thread 1: unregistration completes, `nameA` is removed from `registeredBeans`
##### expected
* `registeredBeans` should be a `Set` of all registered MBeans
##### observed
* `nameA` is registered but is not present in `registeredBeans`
* later call to `MBeanExporter.destroy()` (like application redeployment) will leave `nameA` registered in the server
Affects: 3.1.2, 3.1.4
Referenced from: commits 1ea218c, 8d6d6be
Backported to: 3.2.6