Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable is already defined in method #2478

Closed
1 task done
cdalexndr opened this issue Jun 10, 2021 · 2 comments · Fixed by #2480
Closed
1 task done

variable is already defined in method #2478

cdalexndr opened this issue Jun 10, 2021 · 2 comments · Fixed by #2480
Assignees
Labels
Milestone

Comments

@cdalexndr
Copy link

cdalexndr commented Jun 10, 2021

  • Is this an issue (and hence not a question)?

Mapping:
abstract JPAProduct productFromDto( Product dto, @Context Language language, @Context Shop shop );

generates:

  JPAProduct productFromDto(Product dto, Language language, Shop shop) {
        ...
        jPAProduct.setShop( shopToJPAShop( dto.getShop(), language, shop ) );

where the generated shopToJPAShop method has duplicate variable name:
protected JPAShop shopToJPAShop(Shop shop, Language language, Shop shop) {

Compile error:
error: variable shop is already defined in method shopToJPAShop(Shop,Language,Shop)

MapStruct version: 1.4.2.Final

@cdalexndr
Copy link
Author

Workaround, add explicit mapping method:
abstract JPAShop fromShop( Shop shop );
then this method will be used instead of the invalid generated one.

filiphr added a commit to filiphr/mapstruct that referenced this issue Jun 12, 2021
@filiphr filiphr added the bug label Jun 12, 2021
@filiphr filiphr self-assigned this Jun 12, 2021
@filiphr filiphr added this to the 1.5.0 milestone Jun 12, 2021
@filiphr
Copy link
Member

filiphr commented Jun 12, 2021

Good catch @cdalexndr. There is a PR for fixing the problem.

Apart from adding an explicit method a workaround will be to change the name of the @Context parameter.

e.g

abstract JPAProduct productFromDto( Product dto, @Context Language language, @Context Shop contextShop );

filiphr added a commit to filiphr/mapstruct that referenced this issue Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants