-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Lombok + @Introspected generates incorrect parameter names #1566
Comments
Pretty sure this is an issue with Lombok. When we are reading the class the parameter name is not there |
We can only process what Lombok gives us. This seems to be a Lombok issue as it |
Possibly the problem is that both annotation processors are in the same round. Together with MapStruct, we've been working on a way to have multiple annotation processors that have to run in a specific order, including to run in a next round. Could this be the case here as well? Alternatively, did someone try to generate a java file using an annotation processor that contains the |
@rspilker MapStruct currently works with Micronaut, we had some issues with earlier versions, but they seem to be resolved now. We currently write out bean definitions when processing is over https://github.com/micronaut-projects/micronaut-core/blob/master/inject-java/src/main/java/io/micronaut/annotation/processing/BeanDefinitionInjectProcessor.java#L219 However, in this case the issues appears to be that lombok is creating a constructor in the AST that is not representing the constructor arguments as the field name. The name of the constructor argument should be How does lombok mutate the AST to produce this new node? When it does so does it use the field name to create the |
I have this issue too. First I though that this could be solved with java.beans.ConstructorProperties that Lombok can generate on constructor. Micronaut currently does not support reading that annotation, but it could. Although after some hacking Micronaut code I figured that annotations generated by Lombok are also not visible from on constructor. @rspilker do you have any hint how this could be solved for Micronaut? |
It seems that this is a Micronaut's issue. I hacked Micronaut code a bit and enabled IntrospectedTypeElementVisitor only when If you run Although in this case |
Annotation processor order is important. The Lombok processor needs to be declared before the Micronaut one so that it runs first |
In case, when you use Lombok's Simple reproducer: https://github.com/asodja/micronaut-lombok-reproducer. I think MapStruct has similar issues and has special interface that is implemented by Lombok: |
I have similar issue with adding I can see the disassembled file is correctly generated by Lombok by Micronaut's classes are missing the annotation and fields with lost names. It would be nice to have it working. |
I did some investigation and it looks like a new constructor generated in Lombok doesn't have parameter names and annotations but if the processing is deferred to the next round they are present. @rspilker Any idea why is this happening? Doesn't look like it's Micronaut related, the processing order is correct otherwise there wouldn't be a constructor present. @graemerocher I have a possible solution to defer introspected processing for classes with Lombok dstepanov@27f71c7 |
Interesting, seems a bit hacky, would be interested to hear @rspilker comments on this |
Maybe it's worth reading: mapstruct/mapstruct#510 (comment) (and other comments in this issue). It seems like similar issue. Tl;dr of how they solved it can be found here: projectlombok/lombok#973 (comment) |
Found the problem to be in Lombok projectlombok/lombok#2497 |
Thanks for the looking into that @dstepanov I don't personally think we should place hacks into Micronaut to workaround issues in Lombok so would greatly prefer this to be fixed upstream |
This was fixed upstream |
Sorry to post to a closed Issue, but I discovered an unexpected behaviour that might of interest. I posted my findings in the lombok issue projectlombok/lombok#2497 Note: I do not use @introspected but @MappedEntity instead so it might not be the exact same issue. |
@altery Your latest post #1566 (comment) links back to this very post. |
Thanks for noticing, @SchulteMarkus , the link is now corrected 🙈 |
Confirmed fixed with (finally released) |
Summary
The TLDR is that this simple class
leads to different parameter names:
The longer version is that a
application.yml
:and a controller:
fails when doing:
POST /bad
with a stack trace like:
It fails in both
gradle
andmaven
.Strangely, it works in
eclipse
.Steps to Reproduce
git clone https://github.com/achaphiv/micronaut-introspection-issue
./gradlew test -i
or./mvnw test
Expected Behaviour
Tests should pass.
Actual Behaviour
Tests fail.
Environment Information
Example Application
https://github.com/achaphiv/micronaut-introspection-issue
The text was updated successfully, but these errors were encountered: