Visitar URL original
#3936 Throw exhaustive exception for fully-covered sealed source by henriquejsza · Pull Request #4147 · mapstruct/mapstruct · GitHub
Skip to content

#3936 Throw exhaustive exception for fully-covered sealed source - #4147

Open
henriquejsza wants to merge 1 commit into
mapstruct:mainfrom
henriquejsza:3936-sealed-subclass-exhaustive
Open

henriquejsza wants to merge 1 commit into
mapstruct:mainfrom
henriquejsza:3936-sealed-subclass-exhaustive

Conversation

@henriquejsza

Copy link
Copy Markdown

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 using default values, producing an
object in a potentially invalid state (and emitting a spurious "Unmapped target
property" warning). Example from the issue: new To(null) for a non-null record
component.

The else branch now throws the configured subclassExhaustiveStrategy
exception 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

…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>
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.

@SubclassMapping does not throw IllegalArgumentException when sealed source has subclasses and target does not

1 participant