Skip to content

[class-parse] Fix member-type and CheckForNull nullability - #13305

Merged
jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-jspecify-nullable-fixes
Oct 28, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-jspecify-nullable-fixes

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

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 and CheckForNull finding 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.

Tested after rebasing onto current main:

  • dotnet test external\Java.Interop\tests\Xamarin.Android.Tools.Bytecode-Tests\Xamarin.Android.Tools.Bytecode-Tests.csproj -v minimal -p:JavaCPath="$($env:JAVA_HOME)bin\javac.exe" -p:JarPath="$($env:JAVA_HOME)bin\jar.exe" — 107 passed, 2 skipped. The existing documentation tests require ANDROID_SDK_PATH, which is unset.
  • git diff --check origin/main...HEAD — passed.

Honor INNER_TYPE-only annotation paths without applying nested type annotations to their containers. Recognize javax and FindBugs CheckForNull contracts in null-marked scopes.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the nullability metadata changes.

No open issues 🎉

What changed in this PR

Fixes class-parse nullability metadata for member-type references and explicit @CheckForNull contracts inside @NullMarked scopes.

Changes:

  • Accepts empty and INNER_TYPE-only annotation paths without applying generic-argument or array-element nullability to their containers.
  • Recognizes both javax.annotation.CheckForNull and FindBugs CheckForNull.
  • Adds nine regression cases covering fields, returns, and parameters.
File Description
external/​Java.Interop/​tests/​Xamarin.Android.Tools.Bytecode-Tests/​JSpecifyAnnotationTests.cs Adds parameterized nullability assertions for nine cases.
external/​Java.Interop/​tests/​Xamarin.Android.Tools.Bytecode-Tests/​java/​javax/​annotation/​CheckForNull.java Adds the javax annotation test fixture.
external/​Java.Interop/​tests/​Xamarin.Android.Tools.Bytecode-Tests/​java/​edu/​umd/​cs/​findbugs/​annotations/​CheckForNull.java Adds the FindBugs annotation test fixture.
external/​Java.Interop/​tests/​Xamarin.Android.Tools.Bytecode-Tests/​java/​com/​jspecifytest/​JSpecifyPackageMarked.java Adds member-type, generic, array, and annotation fixtures.
external/​Java.Interop/​src/​Xamarin.Android.Tools.Bytecode/​XmlClassDeclarationBuilder.cs Recognizes both CheckForNull annotations as nullable.
external/​Java.Interop/​src/​Xamarin.Android.Tools.Bytecode/​TypeAnnotation.cs Treats INNER_TYPE-only paths as applying to the reference itself.

Review effort: Balanced

@jonathanpeppers
jonathanpeppers merged commit aa61ae1 into main Oct 28, 2026
42 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-jspecify-nullable-fixes branch October 28, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants