check-flagged-apis: make interfaces inherit from java/lang/Object
When parsing API signature files, check-flagged-apis relies on ClassItem.superClass to get the parent class of a class or interface. That method always returns null for interfaces. When generating api-versions.xml, metalava marks interface classes as inheriting from java/lang/Object: <class name="android/os/Parcelable" since="1"> <extends name="java/lang/Object"/> [...] </class> This confuses check-flagged-apis when comparing data parsed from both sources, as the symbol signatures will be identical, but the superclass entries differ. Work around this by explicitly marking all interfaces as inheriting from java/lang/Object when parsing API signature files. Bug: 334870672 Test: atest --host check-flagged-apis-test Change-Id: Icbb8f7d4c3d4232a083289a778b347e33a0856ab
This commit is contained in:
@@ -120,6 +120,26 @@ class CheckFlaggedApisTest {
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParseApiSignatureInterfacesInheritFromJavaLangObject() {
|
||||
val apiSignature =
|
||||
"""
|
||||
// Signature format: 2.0
|
||||
package android {
|
||||
@FlaggedApi("android.flag.foo") public interface Interface {
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trim()
|
||||
val expected =
|
||||
setOf(
|
||||
Pair(
|
||||
Symbol.createClass("android/Interface", "java/lang/Object", setOf()),
|
||||
Flag("android.flag.foo")))
|
||||
val actual = parseApiSignature("in-memory", apiSignature.byteInputStream())
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParseFlagValues() {
|
||||
val expected: Map<Flag, Boolean> =
|
||||
|
@@ -205,7 +205,11 @@ internal fun parseApiSignature(path: String, input: InputStream): Set<Pair<Symbo
|
||||
val symbol =
|
||||
Symbol.createClass(
|
||||
cls.baselineElementId(),
|
||||
cls.superClass()?.baselineElementId(),
|
||||
if (cls.isInterface()) {
|
||||
"java/lang/Object"
|
||||
} else {
|
||||
cls.superClass()?.baselineElementId()
|
||||
},
|
||||
cls.allInterfaces()
|
||||
.map { it.baselineElementId() }
|
||||
.filter { it != cls.baselineElementId() }
|
||||
|
Reference in New Issue
Block a user