This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Repository navigation
[release/10.0.1xx] Support JSpecify nullness annotations - #1509
Merged
jonathanpeppers merged 1 commit intoOct 28, 2026
Merged
jonathanpeppers merged 1 commit into
jonathanpeppers merged 1 commit into
Conversation
Backport #1483, including its review fixes for explicit nullable contracts, type-variable uses, and merged parameter annotations. Parse TYPE_USE annotations and apply class/package nullness defaults to returns, parameters, and fields. Retain the release parameter-output path without the unrelated main-only Kotlin inline-class helper. Keep the upstream scope limitations unchanged. (cherry picked from commit d6951e4) Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unhandled CheckForNull annotations and discarded nested-type nullability annotations cause explicitly nullable fields, returns, and parameters to receive incorrect non-null XML attributes in @NullMarked scopes.
2 open issues
What changed in this PR
Backports JSpecify nullness support to release/10.0.1xx, enabling the bytecode parser to preserve nullability contracts in API XML used for generated bindings.
Changes:
- Parses Java type-use annotations and runtime-visible parameter annotations.
- Applies class and package nullness defaults while honoring explicit nullable annotations and excluding
package-infofrom API types. - Adds nullability fixtures and regression tests while preserving the release branch’s parameter-output path.
| File | Description |
|---|---|
| tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj | Embeds compiled JSpecify fixtures. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/JSpecifyAnnotationTests.cs | Tests nullness resolution and annotation parsing. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/org/jspecify/annotations/NullUnmarked.java | Adds a nullness-scope opt-out fixture annotation. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/org/jspecify/annotations/NullMarked.java | Adds a non-null scope fixture annotation. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/org/jspecify/annotations/Nullable.java | Adds a nullable type-use fixture annotation. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/org/jspecify/annotations/NonNull.java | Adds a non-null type-use fixture annotation. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/jspecifyunmarked/JSpecifyUnmarked.java | Exercises explicit annotations without scope defaults. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/jspecifytest/package-info.java | Defines a null-marked package fixture. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/jspecifytest/JSpecifyPackageMarked.java | Exercises package defaults and nullable exceptions. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/jspecifytest/JSpecifyClassMarked.java | Exercises class defaults and nullable exceptions. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/java/androidx/annotation/Nullable.java | Adds a declaration-level nullable fixture annotation. |
| src/Xamarin.Android.Tools.Bytecode/XmlClassDeclarationBuilder.cs | Resolves member nullness for XML output. |
| src/Xamarin.Android.Tools.Bytecode/TypeAnnotation.cs | Parses type-annotation targets and path lengths. |
| src/Xamarin.Android.Tools.Bytecode/ClassPath.cs | Forwards package metadata and excludes package-info types. |
| src/Xamarin.Android.Tools.Bytecode/ClassFile.cs | Identifies package-info class files. |
| src/Xamarin.Android.Tools.Bytecode/AttributeInfo.cs | Registers and parses additional annotation attributes. |
Review effort: Balanced
simonrozsival
approved these changes
Oct 28, 2026
jonathanpeppers
deleted the
jonathanpeppers-jspecify-servicing-backport
branch
October 28, 2026 20:18
jonathanpeppers
added a commit
to dotnet/android
that referenced
this pull request
Oct 28, 2026
…13305) Inside `@NullMarked` scopes, class-parse incorrectly marks `Outer.@nullable Inner` references and explicit `@CheckForNull` contracts as non-null. This affects fields, returns, and parameters. Accept empty or `INNER_TYPE`-only annotation paths, while keeping annotations on generic arguments and array elements separate from container nullability. Recognize both `javax.annotation.CheckForNull` and `edu.umd.cs.findbugs.annotations.CheckForNull`. Fixes the [member-type finding](dotnet/java-interop#1509 (comment)) and [CheckForNull finding](dotnet/java-interop#1509 (comment)) from dotnet/java-interop#1509. That servicing PR is unchanged. Added nine regression cases covering fields, returns, and parameters, including mixed member-type, generic, and array paths. Co-authored-by: Copilot App <[email protected]>
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Backports #1483 (d6951e4) to
release/10.0.1xxas a single commit.Adds parsing for JSpecify
TYPE_USEannotations and class/package nullness defaults so generated API XML preserves non-null returns, parameters, and fields while respecting explicit nullable contracts. This addresses the parser gap behind dotnet/android-libraries#1558 and dotnet/android-libraries#1559 without per-library metadata overrides.The only release-specific adaptation keeps the existing parameter-output path without the unrelated Kotlin inline-class helper from
main. Upstream scope limitations remain unchanged. No Android submodule update is included.Validation
ANDROID_SDK_PATH.class-parseon the compiled fixture JAR. Checked non-null returns and parameters, explicit nullable contracts, type-variable handling, nested nullable handling, and exclusion ofpackage-infofrom API types.