From 581f2e5f79c757d6f351fa57e5e4896002211a10 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 22 Sep 2021 13:25:23 +0100 Subject: Detect duplicates in sdkRegistry Bug: 195754365 Test: m nothing Change-Id: I67c5022b7cc61891fd6b90365f8271d97d7bcd98 --- android/sdk.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'android/sdk.go') diff --git a/android/sdk.go b/android/sdk.go index 1518a8731..1d63d7a94 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -396,6 +396,25 @@ type sdkRegistry struct { func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry { oldList := r.list + // Make sure that list does not already contain the property. Uses a simple linear search instead + // of a binary search even though the list is sorted. That is because the number of items in the + // list is small and so not worth the overhead of a binary search. + found := false + newPropertyName := registerable.SdkPropertyName() + for _, r := range oldList { + if r.SdkPropertyName() == newPropertyName { + found = true + break + } + } + if found { + names := []string{} + for _, r := range oldList { + names = append(names, r.SdkPropertyName()) + } + panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names)) + } + // Copy the slice just in case this is being read while being modified, e.g. when testing. list := make([]sdkRegisterable, 0, len(oldList)+1) list = append(list, oldList...) -- cgit v1.2.3-59-g8ed1b