From aa41dac8d85e5a90e0d7f3aa17801478bbce45e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Wed, 22 May 2024 15:13:54 +0200 Subject: [PATCH] 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: [...] 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 --- .../checkflaggedapis/CheckFlaggedApisTest.kt | 20 +++++++++++++++++++ .../src/com/android/checkflaggedapis/Main.kt | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt index 111ea91f85..8e285f6216 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt @@ -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 = diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt index a277ce815f..1d2440dee8 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt @@ -205,7 +205,11 @@ internal fun parseApiSignature(path: String, input: InputStream): Set