Throw IllegalStateException when inserting an existing item

This commit throws IllegalStateException instead of
IllegalArgumentException when inserting an existing item
to TestBpfMap to fit the current behavior in the
production code.

This is safe given that this is only for test and no one is
currently check the exception.

Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Bug: 354619988
Change-Id: I1e5c6e99a0d95b44dd556de8805bb16c3d1a4f61
This commit is contained in:
Junyu Lai 2024-09-04 18:45:00 +08:00
commit c1856de66e

View file

@ -65,10 +65,11 @@ public class TestBpfMap<K extends Struct, V extends Struct> implements IBpfMap<K
@Override
public void insertEntry(K key, V value) throws ErrnoException,
IllegalArgumentException {
// The entry is created if and only if it doesn't exist. See BpfMap#insertEntry.
IllegalStateException {
// The entry is created if and only if it doesn't exist.
// And throws exception if it exists. See BpfMap#insertEntry.
if (mMap.get(key) != null) {
throw new IllegalArgumentException(key + " already exist");
throw new IllegalStateException(key + " already exist");
}
mMap.put(key, value);
}