Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dd52ce6 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix bug in ArrayUtils.filter.

ArrayUtils.filter is only supposed to return elements that satisfed the
predicate but it was incorrectly returning everything if nothing
satisfed the predicate.

Bug: 169854982
Test: Android builds
Change-Id: Ia6bd553922ff5823778e5865b6431c6f07aca334
parent e9988880
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -760,6 +760,7 @@ public class ArrayUtils {

    /**
     * Returns an array containing elements from the given one that match the given predicate.
     * The returned array may, in some cases, be the reference to the input array.
     */
    public static @Nullable <T> T[] filter(@Nullable T[] items,
            @NonNull IntFunction<T[]> arrayConstructor,
@@ -775,16 +776,13 @@ public class ArrayUtils {
                matchesCount++;
            }
        }
        if (matchesCount == 0) {
            return items;
        }
        if (matchesCount == items.length) {
            return items;
        }
        T[] result = arrayConstructor.apply(matchesCount);
        if (matchesCount == 0) {
            return null;
            return result;
        }
        T[] result = arrayConstructor.apply(matchesCount);
        int outIdx = 0;
        for (int i = 0; i < size; i++) {
            if (predicate.test(items[i])) {