Skip to content

Handle no suitable empty constructor during BeanMappingMethod creation#1287

Merged
filiphr merged 2 commits into
mapstruct:masterfrom
filiphr:1283
Sep 7, 2017
Merged

Handle no suitable empty constructor during BeanMappingMethod creation#1287
filiphr merged 2 commits into
mapstruct:masterfrom
filiphr:1283

Conversation

@filiphr
Copy link
Copy Markdown
Member

@filiphr filiphr commented Sep 3, 2017

Fixes #1283.

This PR fixes #1283 by moving the no suitable empty constructor check during the BeanMappingMethod creation (only if there is no factory method). With this we additionally get the same check for non-reverse methods and BeanMapping#resultType

Copy link
Copy Markdown
Member

@agudian agudian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I just have a minor comment on the wording and I wonder what happens if there is only an inaccessible non-private constructor available (default visibility or package visibility)...

for ( ExecutableElement constructor : constructors ) {
if ( (constructor.getModifiers().contains( Modifier.PUBLIC )
|| constructor.getModifiers().contains( Modifier.PROTECTED ) )
if ( !constructor.getModifiers().contains( Modifier.PRIVATE )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know here that the constructor is actually accessible from the package of the mapper?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the case, we don't really know. And I think it is difficult to check this because the test is later on. Actually one of our test have package protected classes and package protected static classes. The modifiers are then empty (and that is why it started failing).

I am not sure if it is worth it to add more complex checks? It will create a compile problem in the generated file in any case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that’s okay as well.

GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ),
GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ),
GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ),
GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have a suitable empty constructor." ),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can omit the “suitable”, as you already mention “empty”. Maybe add “visible” or “accessible”?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree "accessible" sounds better than "suitable". I'll change it. Do you think that we need to give a suggestion what they should do? To me it is pretty clear, but I don't know 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it’s pretty obvious... 🙂

@agudian
Copy link
Copy Markdown
Member

agudian commented Sep 6, 2017

Looks good! Feel free to squash and merge!

@filiphr filiphr merged commit 779c16c into mapstruct:master Sep 7, 2017
@filiphr filiphr deleted the 1283 branch September 7, 2017 15:44
@filiphr
Copy link
Copy Markdown
Member Author

filiphr commented Sep 7, 2017

Thanks a lot for the review @agudian

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: @InheritInverseConfiguration --> There is no suitable result type constructor for reversing this method

2 participants