Skip to content

Handle JSpecify type-use nullness for container elements - #4117

Open
exijn wants to merge 1 commit into
mapstruct:mainfrom
exijn:issue-4035-jspecify-type-use
Open

exijn wants to merge 1 commit into
mapstruct:mainfrom
exijn:issue-4035-jspecify-type-use

Conversation

@exijn

@exijn exijn commented Aug 25, 2026

Copy link
Copy Markdown

Description

JSpecify type-use nullness on array components and collection elements was not preserved when MapStruct resolved container mapping methods. This caused generated element mappings to invoke a non-null mapping method with a nullable array or collection element.

Changes

  • Preserve nested JSpecify type-use mirrors at the container mapping boundary, falling back to the declaration mirror when the compiler's member-substituted executable type omits the annotations.
  • Resolve source and target element nullability in the mapper's JSpecify scope and apply the existing nullability contract when wrapping iterable and array assignments.
  • Keep the change internal; no public API or type model SPI changes are introduced.

Generated code impact

Generated array and iterable mappings now guard nullable source elements before invoking an element mapping method and retain null elements when the target element type permits null. Top-level container nullness and non-JSpecify nullability behavior remain unchanged.

Tests

  • JSpecify type-use regression test covering nullable arrays, nullable array elements, nullable List elements, and nested List elements.
  • Generated source fixture comparison.
  • JSpecify nullability tests: 108 tests passed with javac and Eclipse JDT.
  • Full processor test suite: 3,645 tests passed with javac and Eclipse JDT.
  • Processor verify: checkstyle, license/API checks, forbidden API checks, japicmp, and reactor verification passed.

Tested on Java 25; the processor continues to compile with Java 8 source/target compatibility and uses the repository's Java 21 test baseline.

Fixes #4035

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.

Review JSpecify nullness on type user array elements and lists

1 participant