Skip to content

#4038 Require adder element name to match property name in Type#getAdderForType - #4160

Open
mohit32886 wants to merge 1 commit into
mapstruct:mainfrom
mohit32886:fix/4038-adder-property-matching
Open

mohit32886 wants to merge 1 commit into
mapstruct:mainfrom
mohit32886:fix/4038-adder-property-matching

Conversation

@mohit32886

Copy link
Copy Markdown

Fixes #4038

Summary

  • Previously, Type#getAdderForType(Type, String) returned the single type-compatible adder candidate unconditionally whenever candidates.size() == 1, without checking whether the adder's element name matched the target property name.
  • When a target bean or builder had one collection property with an adder (e.g. items / addItem(String)) and another collection property of the same element type without an adder (e.g. moreItems with setMoreItems or a fluent builder method), MapStruct selected the unrelated addItem adder for moreItems as well.
  • Removed the candidates.size() == 1 shortcut and matched candidate adders by singularized property name (Nouns.singularize(pluralPropertyName)), falling back to the exact plural property name (pluralPropertyName, e.g. addTeeth for teeth) if no singularized match exists.

Tests

  • Added regression tests in org.mapstruct.ap.test.bugs._4038.Issue4038Test covering JavaBean targets, builder targets, getter-only fallback, and Dali plural fallback (addTeeth alongside moreTeeth).
  • Verified locally with mvn license:check and mvn -pl processor -am verify -DskipITs=false (3649 tests, Checkstyle, forbiddenapis, and japicmp all passed).

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.

Mapstruct mapping incorrect properties when one of them is supporting adder

1 participant