Responding to both of your messages at once.....

On Sep 5 2013, at 21:49 , David Holmes wrote:

> Hi Mike,
> 
> On 6/09/2013 2:58 AM, Mike Duigou wrote:
>> Hello all;
>> 
>> A very small spec clarification for review. The spec clarification ensures 
>> that the behaviour of the default method can satisfy the needs of 
>> unmodifiable implementations.
>> 
>> http://cr.openjdk.java.net/~mduigou/JDK-8023340/0/webrev/
> 
> I don't agree with the change. An Unmodifable list _should_ throw UOE.
> 
> That aside I don't know how to interpret you change:
> 
> "operation is not supported by this list for some element"
> 
> What does "for some element" mean ???
> 
> David
> 
>> Thanks,
>> 
>> Mike
>> 

On Sep 6 2013, at 08:35 , Martin Buchholz wrote:

> ListIterator.set is specified to throw these exceptions:
> 
>      * @throws UnsupportedOperationException if the {@code set} operation
>      *         is not supported by this list iterator
>      * @throws ClassCastException if the class of the specified element
>      *         prevents it from being added to this list
>      * @throws IllegalArgumentException if some aspect of the specified
>      *         element prevents it from being added to this list
>      * @throws IllegalStateException if neither {@code next} nor
>      *         {@code previous} have been called, or {@code remove} or
>      *         {@code add} have been called after the last call to
>      *         {@code next} or {@code previous}
> 
> List.replaceAll invokes set (conceptually), so it needs to specify the same 
> exceptions, no?  Many years ago I made an effort to make these sorts of 
> exception specs more consistent and accurate - a good outlet for my inner 
> pedant.  Perhaps that needs to be done once more?  Hmmmmmmm..... I notice the 
> above list is missing NullPointerException; that looks like a bug... (my bad, 
> I think)
> 
> Like David, I don't see the point of this change.

The goal is to allow Collections.emptyList(), Collections.singletonList() and 
possibly other implementations to use the default List.replaceAll 
implementation. I want to avoid having to override the default implementation 
in order to throw UOE. In the case of emptyList() I justify this this by saying 
"the list is empty, so replaceAll matches nothing, no need to throw UOE". For 
singletonList() my goal is to allow the ListIterator.set() to throw the UOE 
exception rather than having to write a UOE throwing replaceAll() method for 
Collections.singletonList().

I significant motivation is that I want to ensure that the specification for 
the defaulted method is written such that the default can satisfy situations 
such as empty or unmodifiable collection--I could "fix" 
Collections.singletonList() but I can't fix every possible unmodifiable list 
and the default implementation can't a priori know that calling the 
ListIterator.set() will or won't throw UOE.

> UOE is not supposed to be at the element level.  If a List or ListIterator 
> doesn't like a particular element, it should be throwing one of the above 
> exceptions (plus NPE).

Yeah, probably a mistake on my part. I will try again at a definition for 
replaceAll() that avoids having to write override and is still coherent.

Thanks,

Mike

> 
> 
> 
> On Thu, Sep 5, 2013 at 9:58 AM, Mike Duigou <mike.dui...@oracle.com> wrote:
> Hello all;
> 
> A very small spec clarification for review. The spec clarification ensures 
> that the behaviour of the default method can satisfy the needs of 
> unmodifiable implementations.
> 
> http://cr.openjdk.java.net/~mduigou/JDK-8023340/0/webrev/
> 
> Thanks,
> 
> Mike
> 

Reply via email to