Skip to content

Honor JSpecify nullability of reused mapping methods - #4110

Open
kush2439p wants to merge 1 commit into
mapstruct:mainfrom
kush2439p:codex/fix-jspecify-assignment-contracts
Open

Honor JSpecify nullability of reused mapping methods#4110
kush2439p wants to merge 1 commit into
mapstruct:mainfrom
kush2439p:codex/fix-jspecify-assignment-contracts

Conversation

@kush2439p

Copy link
Copy Markdown

Summary

Fixes #4106 by carrying the JSpecify input and output contracts of reused mapping methods through generated assignments.

MapStruct previously based null guards primarily on source/target nullability and null-value-check strategy. It did not retain whether a selected helper method required a non-null argument or guaranteed a non-null result, which could generate unsafe calls or reject safe constructor mappings.

Implementation

  • Add internal assignment contracts for the innermost reused-method input and outermost reused-method result.
  • Resolve explicit and scoped JSpecify nullability from selected mapping methods, including methods from uses types.
  • Propagate contracts through method chains and conversion wrappers.
  • Generate a source guard when a nullable value is passed to a non-null helper parameter.
  • Invoke nullable-input/non-null-output helpers directly when they can safely satisfy a non-null target.
  • Validate constructor parameters against the effective assignment result.
  • Preserve legacy behavior for built-ins, forged methods, assignments without method contracts, and -Amapstruct.disableJSpecify=true.
  • Add a verbose diagnostic for guards introduced by reused-method input contracts.
  • Document null propagation and clarify that JSpecify annotations do not participate in overload selection.

This also covers the related scenarios described in #4077, #4081, and #4086 without adding public API.

Verification

  • Full JSpecify*Test suite: 111 tests passed.
  • Focused reused-method, disabled-option, and verbose-diagnostic tests: 13 passed.
  • Constructor contract regression tests: 2 passed.
  • Full processor Surefire results: 3,561 tests, 0 failures, 0 errors.
  • Processor Checkstyle: passed with 0 violations.
  • Targeted MavenIntegrationTest#fullFeatureTest: passed.

The full reactor clean install -DskipDistribution=true exceeded the local 15-minute command limit after the processor suite completed; the affected integration path and Checkstyle were rerun successfully afterward.

@kush2439p
kush2439p marked this pull request as ready for review August 10, 2026 12:44
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.

Be able to generate the nullable mapping from the NotNull mapping

1 participant