Apache OpenOffice (AOO) Bugzilla – Full Text Issue Listing
|Summary:||setName(name) on a bookmark throws an undocumented RuntimeException if the name already exists|
|Component:||code||Assignee:||AOO issues mailing list <issues>|
|Status:||ACCEPTED ---||QA Contact:|
|Priority:||P3||CC:||baumux, chris_mux, issues, kpalagin, mux2005|
|Issue Type:||DEFECT||Latest Confirmation in:||---|
Description clutz 2006-09-20 16:25:19 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
Comment 1 michael.ruess 2006-09-21 07:34:01 UTC
Reassigned to JSK.
Comment 2 kpalagin 2006-11-26 22:14:58 UTC
Confirming with OO 2.0.4 on Win XP - code throws an exception.
Comment 3 joerg.skottke 2007-11-27 14:13:21 UTC
API -> cn
Comment 4 chne 2007-12-03 11:18:58 UTC
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
Comment 5 clutz 2007-12-14 10:45:29 UTC
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.
Comment 6 chne 2008-01-18 09:24:02 UTC
cn->jsc : please take over
Comment 7 jsc 2008-01-18 09:37:47 UTC
jscv -> tl: can you please document the behavior at the Bookmark service.
Comment 8 Oliver Specht 2008-01-18 11:17:42 UTC
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.
Comment 9 thomas.lange 2008-03-14 13:06:07 UTC
Has become a documentation issue.