Documentation of the com.sun.star.uno.XNamingService declares registerObject method automatically revokes previously registered object. Instead DatabaseContext throws com.sun.star.container.ElementExistException with the name if object. Same way XNamingService's revokeObject method declares to do nothing if no object was registered, but instead throws com.sun.star.container.NoSuchElementException.
@Stephan, I thought you might be interested in this issue
@Mike, could you please help with this issue ?
FTR: the definition of the interface behavior is given in udkapi/com/sun/star/uno/XNamingService.idl [1]. The implementation of DatabaseContext's registerObject is in dbaccess/source/core/dataaccess/databasecontext.cxx. After initial argument checks, it calls registerDatabaseLocation, which in turn calls DatabaseRegistrations::registerDatabaseLocation, and the latter calls impl_checkValidName_throw_must_not_exist. So to conform to the documented behavior, DatabaseContext::registerObject should ensure to de-register existing registration for the name before trying to register. Similar for revokeObject. [1] https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1uno_1_1XNamingService.html
By the way, OSDBCDriverManager::registerObject in connectivity/source/manager/mdrivermanager.cxx also throws in this case. Could be fixed in this easy hack. The task includes checking commit history - if it contains hints why were the throws added; and also checking which places call these functions: should they be changed to account for the changed behaviour.