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 }}
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
Commit 18c29b7
Browse filesBrowse the repository at this point in the historyBrowse files
[Xamarin.Android.Tools.Bytecode] Add @not-null support (#526)
Context: #468
Add support for reading `@NotNull`/`@NonNull` annotations from Java
bytecode and inserting them into `api.xml` as `//*/@not-null` and
`//*/@return-not-null` attribute values: `@not-null` is for
parameters and fields, while `@return-not-null` is emitted for method
return values.
Support for `generator` to consume the annotations will be done later.
For example, given the Java code:
// Java:
public class Example {
@nonnull
public static final Creator<DirectAction> CREATOR = /* ... */ ;
public void foo(@nonnull android.os.Handler handler) { /* ... */ }
@nonnull
public Context getContext() { /* ... */ }
}
then `Example.CREATOR` would contain:
<field
deprecated="not deprecated"
final="true"
name="CREATOR"
jni-signature="Landroid/os/Parcelable$Creator;"
not-null="true"
static="true"
transient="false"
type="android.os.Parcelable.Creator"
type-generic-aware="android.os.Parcelable.Creator<android.app.DirectAction>"
visibility="public"
volatile="false" />
The `handler` parameter for `Example.foo()` would contain:
<parameter
name="handler"
type="android.os.Handler"
jni-type="Landroid/os/Handler;"
not-null="true" />
And the `Example.getContext()` method would contain:
<method
abstract="false"
deprecated="not deprecated"
final="true"
name="getContext"
jni-signature="()Landroid/content/Context;"
bridge="false"
native="false"
return="android.content.Context"
jni-return="Landroid/content/Context;"
static="false"
synchronized="false"
synthetic="false"
visibility="public"
return-not-null="true" />
We look for the following annotations:
* Android:
* `android/annotation/NonNull`
* `androidx/annotation/RecentlyNonNull`
* Java:
* `android/support/annotation/NonNull`
* `edu/umd/cs/findbugs/annotations/NonNull`
* `javax/annotation/Nonnull`
* `javax/validation/constraints/NotNull`
* `lombok/NonNull`
* `org/eclipse/jdt/annotation/NonNull`
* `org/jetbrains/annotations/NotNull`
List of annotation types partially taken from:
https://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use
0 commit comments