Skip to content

Fix import ambiguity regression by reordering AddImport/RemoveImport#731

Merged
timtebeek merged 2 commits into
openrewrite:mainfrom
amishra-u:5439_regression
May 19, 2025
Merged

Fix import ambiguity regression by reordering AddImport/RemoveImport#731
timtebeek merged 2 commits into
openrewrite:mainfrom
amishra-u:5439_regression

Conversation

@amishra-u

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

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

amishra-u commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

CI will pass when this change lands.

@timtebeek timtebeek merged commit c7f206a into openrewrite:main May 19, 2025
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 19, 2025

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants