-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android] Add NRT annotations. (#4227)
Context: dotnet/java-interop@01d0684 Annotates all API levels of `Mono.Android.dll` with [C#8 Nullable Reference Type][0] (NRT) annotations, pulled directly from the Java `.jar` files. Additionally, our hand written code has been audited and updated to include NRT annotations. ~~ Notes ~~ There are 8 new warnings caused by this change of the form: Android.Runtime/JavaDictionary.cs(655,24): warning CS8714: The type 'K' cannot be used as type parameter 'TKey' in the generic type or method 'IDictionary<TKey, TValue>'. Nullability of type argument 'K' doesn't match 'notnull' constraint. This is due to the BCL being improperly annotated. The change has since been reverted, but it has not made it into various distribution packs: dotnet/runtime#793 There are a considerable number of warnings (~400) caused by mismatched annotations when members are overridden, such as: CS8610: Nullability of reference types in type of parameter 'baz' doesn't match overridden member. While it may be desirable to fix these, it is a non-trivial job that will be prioritized separately. In the mean time, this set of warnings has been disabled: <NoWarn>8609;8610;8614;8617;8613;8764;8765;8766;8767</NoWarn> Finally, when `$(AndroidGenerateJniMarshalMethods)`=True and `jnimarshalmethod-gen.exe` is executed, the resulting app was crashing because `MagicRegistrationMap.CallRegisterMethodByIndex()` had a parameter change from `int` to `int?`. Fix this by calling `Nullable<int>.GetValueOrDefault()` with the `switch`. `MonoDroidMarkStep.UpdateRegistrationSwitch()` now emits IL like: .method private hidebysig static bool CallRegisterMethodByIndex([Java.Interop]Java.Interop.JniNativeMethodRegistrationArguments arguments, [mscorlib]System.Nullable`1<int32> typeIdx) cil managed { // Code size 9285 (0x2445) .maxstack 2 .locals init ([mscorlib]System.Nullable`1<int32> V_0) IL_0000: ldarg.1 IL_0001: stloc.0 IL_0002: ldloca.s V_0 IL_0004: call instance !0 [mscorlib]System.Nullable`1<int32>::GetValueOrDefault() IL_0009: switch ( … Co-authored-by: Radek Doulik <[email protected]> [0]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
- Loading branch information
Showing
169 changed files
with
1,327 additions
and
1,129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#### Mono.Android.dll Nullable Reference Type Annotations | ||
|
||
`Mono.Android.dll` assemblies of all platform levels are now annotated with | ||
C#8's nullable reference types (NRT). Users who opt their applications into | ||
this feature with `<Nullable>enable</Nullable>` will receive warnings if their | ||
code does not properly account for possible `null` values. | ||
|
||
General documentation for the NRT feature is available here: | ||
https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references. | ||
|
||
Note: | ||
The majority of `Mono.Android.dll` is automatically generated from the Android | ||
Java source, including these new annotations. As such, we will not be manually | ||
fixing places where the Android source code is not annotated correctly. | ||
|
||
If there is an error regarding nullability for any of the Mono.Android APIs | ||
that Xamarin adds to the Android source (such as `JavaList` or `InputStreamAdapter`), | ||
please file a bug so we can properly annotate our additions. |
Submodule Java.Interop
updated
from c19794 to ce8dc4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.