Repository navigation
#3936 Throw exhaustive exception for fully-covered sealed source - #4147
Open
henriquejsza wants to merge 1 commit into
Open
henriquejsza wants to merge 1 commit into
henriquejsza wants to merge 1 commit into
Conversation
…urce When a @SubclassMapping based method has a sealed source hierarchy that is exhaustively covered by the declared mappings, the else branch of the generated method is unreachable. Previously, when every subclass mapped to the same concrete target, MapStruct constructed that target in the else branch with default values, producing an object in a potentially invalid state (and an Unmapped target property warning). The else branch now throws the configured subclassExhaustiveStrategy exception instead of constructing the target, which is consistent with the existing behaviour when the target type is abstract/sealed. Signed-off-by: henriquejsza <henriquejsza@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
@SubclassMappingbased method has a sealed source hierarchy that isexhaustively covered by the declared mappings, the
elsebranch of thegenerated method is unreachable.
Previously, when every subclass mapped to the same concrete target, MapStruct
constructed that target in the
elsebranch using default values, producing anobject in a potentially invalid state (and emitting a spurious "Unmapped target
property" warning). Example from the issue:
new To(null)for a non-null recordcomponent.
The
elsebranch now throws the configuredsubclassExhaustiveStrategyexception instead of constructing the target. This matches the behaviour already
produced when the subclasses map to a sealed/abstract target type, where the
return type cannot be constructed and the exhaustive exception is thrown.
Fixes #3936