You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nullability on returned types from Builders does not match Android API docs and @NotNull annotations #1136
When using some types from the AndroidX packages, I started noticing a lot of method are returning nullable types, while the Android API docs state that they should not be and are annotated with @NonNull.
I noticed in after updating Xamarin.AndroidX.AppCompat to version 1.7.0.6 that all the methods in NotificationCompat.Builder return nullable types.
The exposed C# API looks like this for the same method, where nullability on return type does not match:
// Metadata.xml XPath method reference: path="/api/package[@name='androidx.core.app']/class[@name='NotificationCompat.Builder']/method[@name='setContentTitle' and count(parameter)=1 and parameter[1][@type='java.lang.CharSequence']]"[Register("setContentTitle","(Ljava/lang/CharSequence;)Landroidx/core/app/NotificationCompat$Builder;","GetSetContentTitle_Ljava_lang_CharSequence_Handler")]publicvirtualunsafeglobal::AndroidX.Core.App.NotificationCompat.Builder?SetContentTitle(global::Java.Lang.ICharSequence?title)
Steps to Reproduce
Install Xamarin.AndroidX.AppCompat
Use builder APIs as described above
Did you find any workaround?
Add nullability checks all over the place :'(
Or downgrade to previous version of AppCompat package
Activity
jpobst commentedon May 6, 2025
It looks like the actual package for the referenced API is
Xamarin.AndroidX.Core.Looking at Google's
androidx.core:core 1.15.0.aar, the methods are correctly annotated:However if we look at Google's
androidx.core:core 1.16.0.aar, the annotations are missing:According to their release notes they switched to a new system of "Null" annotations, but I am not seeing them anywhere in the
.aarfile.Cheesebaron commentedon May 7, 2025
Oh, OK. So this is not an issue here I guess. Thanks for clearing this up
Cheesebaron commentedon May 7, 2025
Interestingly when looking at AndroidX.Core 1.16.0 using Android Studio you see:
mathiasi commentedon May 12, 2025
Also noticed this when upgrading to Xamarin.AndroidX.Core 1.16.0.1. Luckily for us we can use 1.15.0.2 to avoid null checks all over the place.
jpobst commentedon May 12, 2025
Opened issue for our tooling to support these new JSpecify annotations: dotnet/java-interop#1335.