Skip to content

#4056 Extend JSpecify support for container mapping and @NonNull return types#4057

Open
filiphr wants to merge 1 commit into
mapstruct:mainfrom
filiphr:4056-jspecify-container-mapping
Open

#4056 Extend JSpecify support for container mapping and @NonNull return types#4057
filiphr wants to merge 1 commit into
mapstruct:mainfrom
filiphr:4056-jspecify-container-mapping

Conversation

@filiphr
Copy link
Copy Markdown
Member

@filiphr filiphr commented May 15, 2026

Summary

Closes #4056.

Extends the JSpecify support added in #4033:

  • @NonNull source on collection-typed property mappings skips the wrapping null guard
  • Container mapping methods (Iterable, Map, Stream) honor JSpecify on their source parameter
  • @NonNull mapping-method return type implies NullValueMappingStrategy.RETURN_DEFAULT semantics across bean, iterable, map and stream mapping methods

All new behaviour is gated on JSpecify annotations and remains fully suppressed by mapstruct.disableJSpecify.

…null return types

Follow-up to mapstruct#1243 closing the gaps reported in mapstruct#4056:

* `@NonNull` source on collection-typed property mappings now skips the
  wrapping null guard around the collection construction (mirrors the
  existing non-collection rule in PropertyMapping).
* Container mapping methods (Iterable, Map, Stream, arrays) now honor
  JSpecify on their source parameter: ContainerMappingMethod and
  MapMappingMethod route the source-parameter presence check through the
  JSpecify-aware PresenceCheckMethodResolver (same helper BeanMappingMethod
  already uses), and the corresponding FTL templates wrap the early-return
  block in <#if sourceParameterPresenceCheck??>.
* `@NonNull` mapping-method return type now implies
  NullValueMappingStrategy.RETURN_DEFAULT semantics across bean, iterable,
  map and stream mapping methods, so generated code never violates a
  @nonnull return contract by emitting `return null`.

All new behaviour is gated on JSpecify annotations being present and is
fully suppressed by the existing `mapstruct.disableJSpecify` option.
@filiphr filiphr force-pushed the 4056-jspecify-container-mapping branch from 26eb64a to 19c830d Compare May 15, 2026 09:26
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.

JSpecify: @NonNull source on collection properties and on container/bean mapping method returns still generates null checks

1 participant