Merge "Disallow adding nested conditional class loader context."

This commit is contained in:
Ulyana Trafimovich 2020-11-16 17:17:05 +00:00 committed by Gerrit Code Review
commit adff039572
2 changed files with 17 additions and 0 deletions

View File

@ -110,6 +110,13 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath)) devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath))
} }
// Nested class loader context shouldn't have conditional part (it is allowed only at the top level).
for ver, _ := range nestedClcMap {
if ver != AnySdkVersion {
clcStr, _ := ComputeClassLoaderContext(nestedClcMap)
return fmt.Errorf("nested class loader context shouldn't have conditional part: %s", clcStr)
}
}
subcontexts := nestedClcMap[AnySdkVersion] subcontexts := nestedClcMap[AnySdkVersion]
// If the library with this name is already present as one of the unconditional top-level // If the library with this name is already present as one of the unconditional top-level

View File

@ -194,6 +194,16 @@ func TestCLCMaybeAdd(t *testing.T) {
}) })
} }
// An attempt to add conditional nested subcontext should fail.
func TestCLCNestedConditional(t *testing.T) {
ctx := testContext()
m1 := make(ClassLoaderContextMap)
m1.AddContextForSdk(ctx, 42, "a", buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "b", buildPath(ctx, "b"), installPath(ctx, "b"), true, m1)
checkError(t, err, "nested class loader context shouldn't have conditional part")
}
func checkError(t *testing.T, have error, want string) { func checkError(t *testing.T, have error, want string) {
if have == nil { if have == nil {
t.Errorf("\nwant error: '%s'\nhave: none", want) t.Errorf("\nwant error: '%s'\nhave: none", want)