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
Redundant null checks for nested properties #3245
Comments
I wouldn't treat this as a bug, but rather as a possible enhancement. I do agree with you that we can optimize this code a bit. The past check can indeed be removed (we need to make sure that it works properly with a presence check still. We can consider this for some future release |
Hi @filiphr. I provided an initial PR that could resolve the redundant nulls checks for nested properties described in the issue. I tested, mostly "manually" the generated mappers and at first glande they look fine. I will wait for the results of the tests suites in the repository Github actions to see if the change breaks something. Please, feel free to make the changes you deem appropriate to the provided code. |
No way @filiphr, the change breaks every fixture based test that is related to nested properties. I will try to fix them and update the PR. |
After adapting the fixtures everything seems to be fine again. |
Expected behavior
Consider this simple DTO and Entity classes:
And a simple mapper:
Generated code should be:
Actual behavior
Generated code is this:
As marked, two additional redundant null checks were generated. The first one makes it impossible to reach full code coverage (unless using Reflection) and the second is just unnecessary code.
Steps to reproduce the problem
No special configuration needed to reproduce this.
MapStruct Version
MapStruct 1.5.4.Final
The text was updated successfully, but these errors were encountered: