Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

[release/10.0.1xx] Support JSpecify nullness annotations - #1509

Merged
jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-jspecify-servicing-backport
Oct 28, 2026
Merged

jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-jspecify-servicing-backport

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Backports #1483 (d6951e4) to release/10.0.1xx as a single commit.

Adds parsing for JSpecify TYPE_USE annotations 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

  • All 15 focused nullability tests passed.
  • Full bytecode test project: 88 passed, 0 failed, 2 skipped. The skipped HTML documentation tests require ANDROID_SDK_PATH.
  • Built and ran class-parse on the compiled fixture JAR. Checked non-null returns and parameters, explicit nullable contracts, type-variable handling, nested nullable handling, and exclusion of package-info from API types.

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]>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-info from 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

@jonathanpeppers
jonathanpeppers merged commit 5c085cf into release/10.0.1xx Oct 28, 2026
3 checks passed
@jonathanpeppers
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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, thanks!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants