-
Notifications
You must be signed in to change notification settings - Fork 354
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: JavaParser fails with StringIndexOutOfBoundsException when lombok processor is enabled #4781
Comments
This is basically the reason we haven't enabled the Lombok processor yet. It appears like it doesn't always adjust the offsets in the AST correctly. I suspect that us a bug in Lombok. So either we need to get it fixed there or we need to adjust our parser so that it tracks the cursor in the file without relying on the AST. |
I think we are actually very close to have this working, we just didn't find the time to complete it. |
If you feel like taking a look at it, I believe that this is where we need to fix things to no longer rely on the position from the AST: Line 1682 in abb80e1
|
Able to reproduce this bug with below unit test, @nonnull to field to cause the error.
|
Thanks for the runnable example @amishra-u ! That should help zero in on the issue. Did you by chance look at a fix as well? |
Yes, I’ve identified the root cause. It’s not an OpenRewrite bug, but rather an issue with the Lombok annotation processor. I added a workaround in OpenRewrite, which resolved the problem. I’m also looking into fixing the underlying issue in Lombok itself and will publish a PR soon. Lombok incorrectly updates the annotation type’s position on a field to the variable’s position in certain scenarios. If you closely look after image it has correct position for annotation but only the annotation type position is updated to the variable’s position. |
Awesome work! Thanks for diving in and posting the outcome here. Keep us posted on any progress with regards to a workaround or fix upstream. |
This method is buggy, it doesn't make deep copy. |
This is also what I observed, but I never analyzed it in detail. Fixing this upstream would be awesome! Hopefully that will then address all such errors in Lombok. |
What version of OpenRewrite are you using?
What is the smallest, simplest way to reproduce the problem?
I haven't debugged the exact root cause yet. the issue seems to occur when annotations are added or removed in the source code. This appears to result in incorrect character positions for the cursor.
(Will add more detail about the issue after debugging)
What did you expect to see?
A valid compilation unit should be generated for the source file.
What did you see instead?
A ParseError instance is generated for the source file instead.
What is the full stack trace of any errors you encountered?
Are you interested in [contributing a fix to OpenRewrite]
Yes.
The text was updated successfully, but these errors were encountered: