-
Notifications
You must be signed in to change notification settings - Fork 360
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
Use regionMatches in isFullyQualifiedClassReference causes wrong results #4773
Comments
hi @ckcd ; I don't know much about the specifics there, so I'm hoping Knut can chime in with at more detailed answer. I do wonder about the ChangeType example that you've given; are you aware there's also a rewrite-jackson module containing that codehaus to fasterxml migration recipe? It might help to look through the implementation there; perhaps it's already handled differently there. |
@timtebeek Thanks for your reply! |
Let me take a look and provide a fix. |
What version of OpenRewrite are you using?
I am using the latest rewrite 8.41.2
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
What is the smallest, simplest way to reproduce the problem?
Below is a very simple test case for using
ChangeType
to change import from:org.codehaus.jackson.annotate.JsonIgnoreProperties
tocom.fasterxml.jackson.annotation.JsonIgnoreProperties
.But in latest version it will failed: it remove the irrelevant import
org.codehaus.jackson.annotate.JsonIgnore
wrongly.As for the reason, I did some troubleshooting, and seems it's because in this commit: e536ed2 we change the behavior of
isFullyQualifiedClassReference
The details:
During the running of this testing recipe, at some point it will call
isFullyQualifiedClassReference
to checkJ.FieldAccess(org.codehaus.jackson.annotate.JsonIgnore)
andString(org.codehaus.jackson.annotate.JsonIgnoreProperties)
, just like below picture shows. Obviously the correct result for this call should befalse
since they are two different class.false
correctly, because in old code in will gotoreturn false
inif (!fieldAccess.getName().getSimpleName().equals(className.substring(className.lastIndexOf('.') + 1)))
true
wrongly, because it cannotreturn false
in theif (!simpleName.regionMatches(0, className, dotIndex + 1, simpleName.length()))
part because theregionMatches
will return true in this case (JsonIgnore
andJsonIgnoreProperties
has the same prefix).So the root cause is, why we use
regionMatches
here? Personally, I think the old code is correct and enough.@knutwannheden @timtebeek @pstreef Please help check this, that's a real serious bug for us.
What did you expect to see?
The expect behavior is it should only replace the
JsonIgnoreProperties
related import.What did you see instead?
But it remove another import
org.codehaus.jackson.annotate.JsonIgnore
wrongly.The text was updated successfully, but these errors were encountered: