On Fri, 19 Apr 2024 22:20:48 GMT, Evemose <d...@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
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. ------------- PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2067354358