summaryrefslogtreecommitdiff
path: root/android/sdk.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-09-22 13:25:23 +0100
committer Paul Duffin <paulduffin@google.com> 2021-09-23 11:37:57 +0100
commit581f2e5f79c757d6f351fa57e5e4896002211a10 (patch)
tree462bea3b6c44aeee1d2238c2b3eba3a592856c4a /android/sdk.go
parentf04033be81f2119f5e07e88912019464912d7641 (diff)
Detect duplicates in sdkRegistry
Bug: 195754365 Test: m nothing Change-Id: I67c5022b7cc61891fd6b90365f8271d97d7bcd98
Diffstat (limited to 'android/sdk.go')
-rw-r--r--android/sdk.go19
1 files changed, 19 insertions, 0 deletions
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...)