Skip to content
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

ChangePackage fails to migrate annotation argument enum in package-info #4174

Merged
merged 3 commits into from
May 9, 2024

Conversation

pativa
Copy link
Contributor

@pativa pativa commented May 8, 2024

What's changed?

I found this issue describing problems with migrating annotations in package-info.java. We seem to still have this problem.

In this MR, I have added a (failing) test showing our issue.

Our actual issue is regarding applying jakarta migration for this class:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://example.com/schema", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.example;

We have made it work using org.openrewrite.java.ChangeType for our migration, but would prefer if org.openrewrite.java.ChangePackage worked for this.

Anything in particular you'd like reviewers to focus on?

Please note that this does not fix the issue, only adds a test case to it :-)

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek
Copy link
Contributor

Thanks a lot! Runnable tests are my favorite way to show a bug; did you already try to step through with a debugger to see if you could pinpoint the source of the issue?

@timtebeek timtebeek added the bug Something isn't working label May 8, 2024
@timtebeek timtebeek changed the title Add failing test for migrating annotation in package-info ChangePackage fails to migrate annotation argument enum in package-info May 8, 2024
@pativa
Copy link
Contributor Author

pativa commented May 8, 2024

No, I haven't found the source of the issue. It seems to find that the types are in use, but the changes are not applied.

I can maybe check it out later if you haven't already found it!

@pativa
Copy link
Contributor Author

pativa commented May 8, 2024

The fix was really simple when I finally found what was going on 🙂

The visitPackage method was not calling super.visitPackage(), so annotations on the package statement weren't being updated.

@pativa pativa marked this pull request as ready for review May 8, 2024 13:16
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense when you see the issue; thanks for digging in and providing the fix!

@pativa
Copy link
Contributor Author

pativa commented May 8, 2024

I'm not really sure of why, but some tests were failing if super.visitPackage() is called.

Instead, I updated the proposed fix to only update the annotations in the same way as is done inside the super method. This seems to work with all the existing tests at least.

@timtebeek timtebeek merged commit 2737893 into openrewrite:main May 9, 2024
1 check passed
@pativa pativa deleted the package-info-annotation branch May 9, 2024 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants