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

SimplifyConstantIfBranchExecution leaves unreachable code #4685

Open
lambm opened this issue Nov 19, 2024 · 1 comment
Open

SimplifyConstantIfBranchExecution leaves unreachable code #4685

lambm opened this issue Nov 19, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail

Comments

@lambm
Copy link

lambm commented Nov 19, 2024

What version of OpenRewrite are you using?

I am using

  • org.openrewrite.recipe:rewrite-static-analysis:1.20.0
  • org.openrewrite.recipe:rewrite-recipe-bom:2.22.0

How are you running OpenRewrite?

Java test case

import org.junit.jupiter.api.Test;
import org.openrewrite.staticanalysis.SimplifyConstantIfBranchExecution;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

class SimplifyTest implements RewriteTest {

    @Test
    void test() {
        rewriteRun(
                spec -> spec.recipe(new SimplifyConstantIfBranchExecution()),
                //language=java
                java(
                        """
                            public class A {
                                public boolean test() {
                                    if (true) {
                                        Object x;
                                        return true;
                                    }
                                    return false;
                                }
                            }
                        """,
                        """
                             public class A {
                                 public boolean test() {
                                     Object x;
                                     return true;
                                 }
                             }
                         """
                )
        );
    }
}

What is the smallest, simplest way to reproduce the problem?

public class A {
    public boolean test() {
        if (true) {
            Object x;
            return true;
        }
        return false;
    }
  }

What did you expect to see?

public class A {
     public boolean test() {
         Object x;
         return true;
     }
 }

What did you see instead?

public class A {
     public boolean test() {
         {
            Object x;
            return true;
         }
         return false;
     }
 }

What is the full stack trace of any errors you encountered?

No error, just invalid output.

Are you interested in contributing a fix to OpenRewrite?

Unable to contribute.

@lambm lambm added the bug Something isn't working label Nov 19, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Nov 19, 2024
@timtebeek
Copy link
Contributor

Thanks for the feedback @lambm ! Great to see that as a runnable example. Indeed a missed case, and would then negatively affect recipes that rely on this too, like rewrite-feature-flags. Appreciate that you're unable to contribute but still wanted to report the issue; I hope in practice at least it was rare? We'll add it to the backlog and hope to get to it soon-ish.

@timtebeek timtebeek added good first issue Good for newcomers test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail labels Nov 19, 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 good first issue Good for newcomers test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail
Projects
Status: Backlog
Development

No branches or pull requests

2 participants