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

Commit 450d8c5b authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #9940105: IllegalArgumentException in ArrayMap

Try to deal with unmarshalling old parcels.  Turns out someone
was writing a parcel to disk storing a Bundle.  Naughty, naughty.
This helps us not completely keel over.

Change-Id: Id343da2690b7bab89f6c3cb6fad1b92f270dad03
parent 597945fd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ public final class Bundle implements Parcelable, Cloneable {
        if (mMap == null) {
            mMap = new ArrayMap<String, Object>(N);
        } else {
            mMap.erase();
            mMap.ensureCapacity(N);
        }
        mParcelledData.readArrayMapInternal(mMap, N, mClassLoader);
+21 −2
Original line number Diff line number Diff line
@@ -246,6 +246,20 @@ public final class ArrayMap<K, V> implements Map<K, V> {
        }
    }

    /**
     * @hide
     * Like {@link #clear}, but doesn't reduce the capacity of the ArrayMap.
     */
    public void erase() {
        if (mSize > 0) {
            final int N = mSize<<1;
            final Object[] array = mArray;
            for (int i=0; i<N; i++) {
                array[i] = null;
            }
        }
    }

    /**
     * Ensure the array map can hold at least <var>minimumCapacity</var>
     * items.
@@ -421,8 +435,13 @@ public final class ArrayMap<K, V> implements Map<K, V> {
            throw new IllegalStateException("Array is full");
        }
        if (index > 0 && mHashes[index-1] > hash) {
            throw new IllegalArgumentException("New hash " + hash
                    + " is before end of array hash " + mHashes[index-1]);
            RuntimeException e = new RuntimeException("here");
            e.fillInStackTrace();
            Log.w(TAG, "New hash " + hash
                    + " is before end of array hash " + mHashes[index-1]
                    + " at index " + index + " key " + key, e);
            put(key, value);
            return;
        }
        mSize = index+1;
        mHashes[index] = hash;