Skip to content

Fix import ambiguity regression by reordering AddImport/RemoveImport #731

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

amishra-u
Copy link
Contributor

@amishra-u amishra-u commented May 19, 2025

What's changed?

PR #5439 introduced logic to detect and handle import ambiguity when adding imports. However, this caused some tests to fail due to the order in which imports were being added and removed in some recipes. When new imports were added before the old ones were removed, this led to false positives for ambiguity, resulting in the use of fully qualified names.

This PR addresses the issue by reordering the maybeAddImport and maybeRemoveImport call. Now maybeRemoveImport precedes the maybeAddImport, to avoid premature ambiguity detection.
Additionally, some unit tests contained genuinely ambiguous imports that went undetected earlier. Fixed those test to align with the improved import resolution logic.

Checklist

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

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite May 19, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 1535-1535
    • lines 1817-1817
    • lines 1825-1825
    • lines 2251-2251
    • lines 2265-2265
    • lines 2443-2503
    • lines 2576-2575

@amishra-u
Copy link
Contributor Author

amishra-u commented May 19, 2025

CI will pass when this change lands.

@timtebeek timtebeek merged commit c7f206a into openrewrite:main May 19, 2025
1 of 2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite May 19, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 1535-1535
    • lines 1817-1817
    • lines 1825-1825
    • lines 2251-2251
    • lines 2265-2265
    • lines 2443-2503
    • lines 2576-2575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants