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

InstanceOfPatternMatch breaks code wrapped in unnecessary parentheses #307

Closed
nazoking opened this issue Jun 29, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@nazoking
Copy link

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v6.16.2
  • Maven/Gradle plugin v6.16.2
  • org.openrewrite.recipe:rewrite-migrate-java:2.18.1

How are you running OpenRewrite?

I am using the Gradle plugin, and my project is a multi module project.

initscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2" }
    }
    dependencies {
        classpath("org.openrewrite:plugin:6.16.2")
    }
}

rootProject {
    plugins.apply(org.openrewrite.gradle.RewritePlugin)
    dependencies {
        rewrite("org.openrewrite.recipe:rewrite-spring:latest.release")
        rewrite("org.openrewrite.recipe:rewrite-migrate-java:2.18.1")
    }

    afterEvaluate {
        if (repositories.isEmpty()) {
            repositories {
                mavenCentral()
            }
        }
    }
}

and run

./gradlew --init-script rewrite.gradle rewriteRun -Drewrite.activeRecipe=org.openrewrite.staticanalysis.InstanceOfPatternMatch

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

A code snippet can be something simple like this.

            if (t instanceof Exception) {
                throw ((Exception) t);
            } else {

What did you expect to see?

            if (t instanceof Exception exception) {
                throw exception;
            } else {

What did you see instead?

            if (t instanceof Exception exception) {
                throwexception;
            } else {

Are you interested in contributing a fix to OpenRewrite?

Indicate if this is something you would like to work on, and how we can best support you in doing so.

@nazoking nazoking added the bug Something isn't working label Jun 29, 2024
@timtebeek
Copy link
Contributor

Thanks for the clear example! I think this should be a relatively straightforward fix, starting with a unit test based on the above. I'd that something you'd want to contribute?

@timtebeek timtebeek transferred this issue from openrewrite/rewrite Jun 29, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jun 29, 2024
@timtebeek timtebeek self-assigned this Jul 15, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Jul 15, 2024
@timtebeek
Copy link
Contributor

Thanks for the clear example @nazoking ; Replicated and fixed in ad28bb1

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

No branches or pull requests

2 participants