commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Rudolf (JIRA)" <>
Subject [jira] Commented: (CONFIGURATION-277) AbstractConfiguration should handle UnsupportedOperationExceptions in Iterator.remove() gracefully
Date Fri, 01 Jun 2007 10:01:25 GMT


Michael Rudolf commented on CONFIGURATION-277:

I don't have problems with a concrete implementation included in Commons Configuration but
I want to create a new implementation. For the getKeys() method I decided to use java.util.Arrays.asList(T...).iterator(),
as I did not want to create a new Iterator implementation to wrap around an array of keys.
However, I then realized that the list created by that method does not support the removal
of items but throws an UnsupportedOperationException instead. Because the iterator calls that
very remove() method it will propagate that runtime exception thus causing the clear() method
to malfunction. The point is that this behavior is perfectly fine, it is documented in the
collections framework. However, the clear method() does not provide for that.

> AbstractConfiguration should handle UnsupportedOperationExceptions in Iterator.remove()
> --------------------------------------------------------------------------------------------------
>                 Key: CONFIGURATION-277
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Michael Rudolf
> Hi,
> In AbstractConfiguration method clear() on line 533 (see code below) a possible UnsupportedOperationException
is not caught resulting in the malfunctioning of the whole method. However, the documentation
of the getKeys() method itself warns about relying on the remove() method of interface Iterator.
The clear() method should not propagate that exception, it should catch it and try the clearProperty(String)
approach if the remove() method is not supported.
>             Iterator it = getKeys();
>             while (it.hasNext())
>             {
>                 String key = (String);
>                 it.remove();                                          <------- EVIL!
>                 if (containsKey(key))
>                 {
>                     // workaround for Iterators that do not remove the property on calling
>                     clearProperty(key);
>                 }
> Best regards,
> Michael

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message