Skip to content

#3390 Apply SET_TO_NULL to existing collections when NullValueCheckStrategy is ALWAYS - #4137

Open
PDGGK wants to merge 1 commit into
mapstruct:mainfrom
PDGGK:fix-3390-set-to-null-existing-collection
Open

PDGGK wants to merge 1 commit into
mapstruct:mainfrom
PDGGK:fix-3390-set-to-null-existing-collection

Conversation

@PDGGK

@PDGGK PDGGK commented Oct 1, 2026

Copy link
Copy Markdown

Fixes #3390.

For update mappings into an existing mutable collection/map, ExistingInstanceSetterWrapperForCollectionsAndMaps currently emits the null-handling else branch only when the null-value check strategy is not ALWAYS. That incorrectly couples whether a source null check is generated to whether the configured null-value property action should run. With NullValueCheckStrategy.ALWAYS, a null source collection therefore leaves a non-null target collection unchanged instead of applying the default SET_TO_NULL behavior.

This change makes the else branch depend only on the null-value property mapping strategy: it is emitted for SET_TO_NULL, SET_TO_DEFAULT, and CLEAR, and remains omitted for IGNORE.

Validation:

  • repository-native Issue3390Test passes across MapStruct's two processor compiler variants
  • reverting only the production change makes both variants fail for the intended stale-collection assertion
  • mvn -B -o -pl processor -am verify -DskipTests passes

Why this is worth doing

#3390 is a reproducible update-mapping correctness bug, not a cosmetic or defensive edge case. The generated mapper silently preserves stale target collection data when the source value is null and NullValueCheckStrategy.ALWAYS is enabled, even though the default update property strategy is SET_TO_NULL. The maintainer previously confirmed that this is a separate bug from #2843 with a different fix. The production change is one predicate in the wrapper that owns this exact generated-code decision, with a small regression fixture reproducing the user's configuration.

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.

Non-null iterable is not updated to NULL

1 participant