[Texo] Autogenerated addTo... fails silently [message #1091575] |
Wed, 21 August 2013 13:33  |
Eclipse User |
|
|
|
Martin,
The auto-generated addTo...() method for List values will fail to add an item
silently if it already exists:
public void addToPasswords(Password passwordsValue) {
if (!passwords.contains(passwordsValue)) {
passwords.add(passwordsValue);
}
}
This can cause unexpected results for the caller who expects the value always to be added. The caller typically expects the given value to be added and then be present in the last item in the list. If the item is present but not the last item, these
expectation will fail.
It would be best to either throw an exception when the item is present and not added or to have the method return true when the item is added or false if its not added. The later would be more compatible with existing users of this method.
- mike
|
|
|
|
|
Re: [Texo] Autogenerated addTo... fails silently [message #1092391 is a reply to message #1092334] |
Thu, 22 August 2013 14:30  |
Eclipse User |
|
|
|
Hi Mike,
Yes I thought of this, but there could be people that have manually changed this method. On the other hand they will get
compile errors when regenerating, these are easy to solve.
Can you enter a bugzilla for this change?
gr. Martin
On 08/22/2013 06:32 PM, Mike Cooper wrote:
> Martin,
>
> A boolean return seems to mean to be completely backwards compatible since its void now. You should also return the
> boolean result from the Collection.add method. So basically something like
>
>
> public boolean addToPasswords(Password item)
> {
> if (!passwords.contains(item)) {
> return passwords.add(item);
> } else {
> return false;
> }
> }
>
>
> I think this should be the default rather than something you manually have to enable in the eattributes. Since this
> method was previously void developers aren't checking the return value at all now.
> - mike
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Powered by
FUDForum. Page generated in 0.20688 seconds