Don't panic if no certificates found

Getting the first certificate will panic if there are no certificates,
which can happen when AllowMissingDependencies is set and the
certificate property is a module reference to a missing module.
Only get the first certificate if the list is not nil.

Use mainCertificate since it handles the logic already.

Test: TestAppMissingCertificateAllowMissingDependencies
Bug: 283102635
Change-Id: I8b27f65aa7d071041171ad45ac52bf47fa31bf2b
This commit is contained in:
Zyan Wu
2023-05-18 15:46:31 +08:00
parent 5050a55b18
commit b7550aa09a
2 changed files with 22 additions and 13 deletions

View File

@@ -3382,6 +3382,14 @@ func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) {
srcs: ["a.java"],
certificate: ":missing_certificate",
sdk_version: "current",
}
android_app {
name: "bar",
srcs: ["a.java"],
certificate: ":missing_certificate",
product_specific: true,
sdk_version: "current",
}`)
foo := result.ModuleForTests("foo", "android_common")