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

Potential endless loop in MaybeUsesImport visitor #601

Open
knutwannheden opened this issue May 7, 2024 · 0 comments
Open

Potential endless loop in MaybeUsesImport visitor #601

knutwannheden opened this issue May 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@knutwannheden
Copy link
Contributor

This bug has been observed, but so far we haven't had any time to reproduce it yet. It appears that the MaybeUsesImport visitor can get caught in an endless loop on some Kotlin sources. The loop in question is this one: https://github.com/openrewrite/rewrite/blob/19c73502d29abe475cb4360f293fbe2e7b3d0027/rewrite-java/src/main/java/org/openrewrite/java/search/MaybeUsesImport.java#L57-L76

            for (Expression expr = i.getQualid(); expr != prior; ) {
                if (expr instanceof J.Identifier) {
                    // this can only be the first segment
                    prior = expr;
                    if (!((J.Identifier) expr).getSimpleName().equals(segment)) {
                        return false;
                    }
                } else if (expr instanceof J.FieldAccess) {
                    J.FieldAccess fa = (J.FieldAccess) expr;
                    if (fa.getTarget() == prior) {
                        String simpleName = fa.getSimpleName();
                        if (!"*".equals(segment) && !simpleName.equals(segment) && !"*".equals(simpleName)) {
                            return false;
                        }
                        prior = fa;
                        continue;
                    }
                    expr = fa.getTarget();
                }
            }
@knutwannheden knutwannheden added the bug Something isn't working label May 7, 2024
knutwannheden added a commit to openrewrite/rewrite that referenced this issue May 7, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite May 9, 2024
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
Status: Backlog
Development

No branches or pull requests

1 participant