Bug 131710

Summary: Undocumented behavior of com.sun.star.sdb.DatabaseContext implementation of com.sun.star.uno.XNamingService
Product: LibreOffice Reporter: Oleg Shchelykalnov <olegshtch>
Component: sdkAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: normal CC: buzea.bogdan, mentoring, mikekaganski, olegshtch, sberg.fun, xiscofauli
Priority: medium Keywords: difficultyMedium, easyHack, skillCpp
Version: 6.4.2.2 release   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:

Description Oleg Shchelykalnov 2020-03-30 13:46:51 UTC
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.
Comment 1 Xisco FaulĂ­ 2020-03-31 12:27:31 UTC
@Stephan, I thought you might be interested in this issue
Comment 2 Xisco FaulĂ­ 2020-11-11 18:54:29 UTC
@Mike, could you please help with this issue ?
Comment 3 Mike Kaganski 2020-11-11 19:54:16 UTC
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
Comment 4 Mike Kaganski 2020-11-12 04:23:43 UTC
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.