Skip to content

Conversation

@filiphr
Copy link
Member

@filiphr filiphr commented Aug 21, 2022

When resolving the parameter for a method like:

<T> Optional<T> from(T value)

There was an exception in javac because getting a DeclaredType from an Optional
with a primitive type argument throws an exception.
Therefore, when assigning the type arguments we get the boxed equivalent.
This problem does not happen in the Eclipse compiler

Fixes #2925

…rameters

When resolving the parameter for a method like:

<T> Optional<T> from(T value)

There was an exception in javac because getting a DeclaredType from an Optional
with a primitive type argument throws an exception.
Therefore, when assigning the type arguments we get the boxed equivalent.
This problem does not happen in the Eclipse compiler
@filiphr
Copy link
Member Author

filiphr commented Aug 21, 2022

@sjaakd it would be good if you can have a look at this. This is in the area you worked on for the generics matching 😄

Copy link
Contributor

@sjaakd sjaakd left a comment

Choose a reason for hiding this comment

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

LGTM. However javadoc could be improved

return null;
}
typeArgs[i] = matchingType.getTypeMirror();
typeArgs[i] = matchingType.getBoxedEquivalent().getTypeMirror();
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this works because if this is not a boxed type it will return type. Perhaps add a comment here. And the javadoc on getBoxedEquivalent should be adapted 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps there are more occasions this situation arises. I believe that I somehow covered the scenario where the target is a generic parameter itself in the testcases. Lets just wait and see if more pop up.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Javadoc says:

Gets the boxed equivalent type if the type is primitive, int will return Integer

What more do you think I should add?

I'll add a comment on the line

@filiphr filiphr merged commit 853e7b2 into mapstruct:main Aug 24, 2022
@filiphr filiphr deleted the 2925 branch August 24, 2022 17:39
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.

Optional wrapping pattern broken in 1.5.2.Final

2 participants