Skip to content

Commit 6aedf1c

Browse files
authored
[Xamarin.Android.Tools.Bytecode] Ignore empty bv values. (#1107)
Fixes: #1106 Context: https://github.com/devtodev-analytics/android-sdk-2.0/blob/ce131e63414d7e6e870c7276c67636fdcfbbd2eb/DTDAnalytics-android%202.3.3/DTDAnalytics-2.3.3.aar We started seeing warnings when parsing newer Kotlin metadata annotations: % dotnet class-parse.dll classes.jar class-parse: warning: Unable to parse Kotlin metadata on 'Utf8("com/devtodev/analytics/external/DTDLogLevel")': System.FormatException: The input string '' was not in a correct format. at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type) at System.Int32.Parse(String s) at Xamarin.Android.Tools.Bytecode.KotlinMetadata.ParseInteger(String value) in …/xamarin/Java.Interop/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs:line 148 at Xamarin.Android.Tools.Bytecode.KotlinMetadata.<>c.<ParseVersion>b__26_0(String v) in …/xamarin/Java.Interop/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs:line 122 at System.Linq.Enumerable.SelectArrayIterator`2.ToArray() at Xamarin.Android.Tools.Bytecode.KotlinMetadata.ParseVersion(Annotation annotation, String key) in …/xamarin/Java.Interop/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs:line 122 at Xamarin.Android.Tools.Bytecode.KotlinMetadata.FromAnnotation(Annotation annotation) in …/xamarin/Java.Interop/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs:line 30 at Xamarin.Android.Tools.Bytecode.KotlinFixups.Fixup(IList`1 classes) in …/xamarin/Java.Interop/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs:line 23 This is because the `bv` entry is set to an empty byte array instead of an empty string, and we are trying to parse its contents as an integer array: `bv: []`. Looking at the [Kotlin source][0], they [decided to deprecate][1] the `bv` value, and it may no longer be supplied: /** * The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation. */ @deprecated( "Bytecode version had no significant use in Kotlin metadata and it will be removed in a future version.", level = DeprecationLevel.WARNING, ) @get:JvmName("bv") val bytecodeVersion: IntArray = [1, 0, 3], We will just silently ignore a missing `bv` value, since we do not consume it. [0]: https://github.com/JetBrains/kotlin/blob/c6d9821ef0746bbbd4c93b7e9c4a2b2468824ce9/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt#L34-L42 [1]: https://youtrack.jetbrains.com/issue/KT-41758
1 parent a91ae7f commit 6aedf1c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public static KotlinMetadata FromAnnotation (Annotation annotation)
116116
{
117117
var value = GetValue (annotation, key);
118118

119-
if (value is null)
119+
// Version is missing or empty
120+
if (value is null || value == "[]")
120121
return null;
121122

122123
var values = value.Trim ('[', ']').Split (',').Select (v => ParseInteger (v)).ToArray ();

0 commit comments

Comments
 (0)