Conversion of BigDecimal to primitive double wrong with 1.5.2
After migrating from 1.4.2 to 1.5.2 a test failed. The result from BigDecimal to double is not the same anymore. Please have a look. Thanks.
https://github.com/urswiss/mapstruct-bigdecimal-to-double
Here is the analysis:
available method to use:
default Long mapAmount(BigDecimal amount) {
return amount.movePointRight(2).longValue();
}
Reason
As it is legal to assign a long to a double, mapstruct will use this method because it is user defined.
Generated code
1.4.2
simpleDestination.setRoundingDiff( source.getRoundingDifference().doubleValue() );
1.5.2
simpleDestination.setRoundingDiff( mapAmount( source.getRoundingDifference() ) );
work around
Use qualifiers to mark the mapAmount method as one specific for certain mappings and use qualfiedBy there to link them.
What will we do about this
I think this is also related to: #2840 and #1216
Because if we pick the exact match, there might be a better workaround by manually creating the default double map(BigDecimal decimal) method.
@filiphr: WDYT ?
Thanks for the analysis @Zegveld. This is most definitely related to #2840 and #1216. We'll need to figure out what actually broke this behaviour.
I think that we need to fix this inconsistency, because mapping from BigDecimal to double shouldn't use BigDecimal to long.
After doing some analysis on this one and #2849 it seems like the work we did in #2320 broke this. I still need to analyse why this happened. This was not supposed to happen when we did that PR. What do you think @sjaakd? It feels like the fact that the return type can be assigned to the expected type is causing the problem.
I am happy to announce that we have managed to find the root cause for this problem and we have a pending fix in #3032