Apache OpenOffice (AOO) Bugzilla – Issue 69706
setName(name) on a bookmark throws an undocumented RuntimeException if the name already exists
Last modified: 2013-08-07 14:44:35 UTC
The following code tries to do a setName(...) call on a bookmark with a name that already exists and OOo throws a RuntimeException. According to the idl-reference, setName() is not allowed to throw any Exceptions!!! There are two ways to fix this problem: 1) change the code, so that setName(name) recognizes a name conflict and sets a different name in the form "name<NUMBER>" (example "foo1") in the same way, the insertContent-command behaves when inserting a bookmark with an already existing name. OR 2a) setName(name) throws an appropriate Exception (eg. IllegalArgumentException, or NameAlreadyExistsException) and not just a RuntimeException. 2b) the IDL-documentation gets a rewrite, so that it reflects the new behaviour and the (new) Exception is documented. Here the code: Sub renameBookmarkError doc = ThisComponent ' insert the first bookmark "foo" bm1 = doc.createInstance("com.sun.star.text.Bookmark") bm1.setName("foo") doc.Text.insertTextContent(doc.Text.Start, bm1, true) ' insert the second bookmark "bar" bm2 = doc.createInstance("com.sun.star.text.Bookmark") bm2.setName("bar") doc.Text.insertTextContent(doc.Text.Start, bm2, true) ' rename bookmark "bar" to "foo" bm2.setName("test") ' works correct print bm2.getName() bm2.setName("foo") ' either generate a new name "foo1" ' or throw a appropriate Exception ' (and not RuntimeException) print bm2.getName() End Sub
Reassigned to JSK.
Confirming with OO 2.0.4 on Win XP - code throws an exception.
API -> cn
css.container.XNamed does not throw a special exception. This is a design issue in the css.container.XNamed idl and can not be fixed anymore. But css.uno.RuntimeException is allowed as back door. See correspond idl. => invalid
this is still a documentation issue as the service css.text.Bookmark implements the Interface css.container.XNamed, but the described behaviour is not documented in the corresponding idl-description. The documentation of css.text.Bookmark should clearly state that renaming a bookmark leeds to a RuntimeException if the name already exists. I dont think this behaviour is intuitive and consistent, as other implementations might be able to dissolve name conflicts. In fact there are methods that behave more inteligent in case of name conflicts (eg. when creating a new Bookmark with a name that already exists, the new name is "name <number>"). So I think it's worth to document this behaviour in the service that implements XNamed.
cn->jsc : please take over
jscv -> tl: can you please document the behavior at the Bookmark service.
The interface XNamed doesn't mention conflicts. It just requires the object's name to be unique within the container. The documentation of css::container::XNamed should be improved. From my POV it is no acceptable solution to reinterprete the Name argument into some arbitrary Name+<index> argument. The caller of a function must be able to rely on the result of the operation. If I call setName("x") and the function doesn't throw then the object _must_ be names "x" now. The user of this interface has to check the container if a name is already in use.
Has become a documentation issue.