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

Commit dbc7cb5c authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Only complain when overwriting with a different value

TimeSparseArray only stores one value per timestamp. It complains when a
value is overwritten to ensure that callers do not lose data
unintentionally. However, when a caller may overwrite a value by itself,
it is less risky, even though redundant. Reducing the severity of the
log in this case.

Test: FrameworksCoreTests:TimeSparseArrayTest

Bug: 279599693
Change-Id: If91be39b2c5d7042d0bc6f6afc5313194b8dfbf8
parent 27e6e4bc
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.util;

import java.util.Objects;

/**
 * An array that indexes by a long timestamp, representing milliseconds since the epoch.
 * @param <E> The type of values this container maps to a timestamp.
@@ -65,9 +67,13 @@ public class TimeSparseArray<E> extends LongSparseArray<E> {
     */
    @Override
    public void put(long key, E value) {
        if (indexOfKey(key) >= 0) {
            if (!mWtfReported) {
                Slog.wtf(TAG, "Overwriting value " + get(key) + " by " + value);
        final int index = indexOfKey(key);
        if (index >= 0) {
            final E curValue = valueAt(index);
            if (Objects.equals(curValue, value)) {
                Log.w(TAG, "Overwriting value at " + key + " by equal value " + value);
            } else if (!mWtfReported) {
                Slog.wtf(TAG, "Overwriting value " + curValue + " by " + value + " at " + key);
                mWtfReported = true;
            }
        }