RFR: 8329760: Add indexOf(Predicate<? super E> filter) to java.util.List interface [v11]
Evemose
duke at openjdk.org
Tue Apr 23 13:54:43 UTC 2024
On Fri, 19 Apr 2024 22:27:15 GMT, xxDark <duke at openjdk.org> wrote:
>>> I noticed that most (if not all) methods don't ensure non-nullability of `filter` so NPE would only be thrown if the list is not empty.
>>
>> Yeah, thats true. not sure if it has to throw NPE even if list is emply
>
>> > I noticed that most (if not all) methods don't ensure non-nullability of `filter` so NPE would only be thrown if the list is not empty.
>>
>> Yeah, thats true. not sure if it has to throw NPE even if list is emply
>
> Yes, it does. If it shouldn't, then why isn't code in the java.util.List is like this:
>
> default int findIndex(Predicate<? super T> filter) {
> ListIterator<T> iterator = listIterator();
> if (!iterator.hasNext()) return -1;
> Objects.requireNonNull(filter);
> int index = 0;
> do {
> if (filter.test(iterator.next()))
> return index;
> index++;
> } while (iterator.hasNext());
> return -1;
> }
>
> Also see methods like `removveIf`. All methods should do checks even if they essentially do nothing.
@xxDark Added null asserions everywhere except sublists that delegate execution to other lists, except for SynchroziedLsit so it doesnt acquire monitor with invalid predicate. I think this would be the best choice
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2067762652
More information about the compiler-dev
mailing list