Skip to content

Remove all UseVarFor* from JavaBestPractices #1043

@scaythe

Description

@scaythe

I'm classifying this as a bug as I think that the current functionality is a mistake, although the behavior is as expected given the choice that was made previously.

Local-Variable Type Inference is a good feature, there are cases where it is very reasonable to use it. The JavaBestPractices recipe calls these cases "non-controversial uses", but I think that while it's uncontroversial that, in these cases, var can be used, it's a lot more controversial to say that for these cases it should be used, everywhere, indiscriminately.

I have no problem with these UseVarFor* recipes, some teams might want to use them, I might use them at some point, but having them in the JavaBestPractices feels contrary to what is expected given the name of the recipe.

What version of OpenRewrite are you using?

I am using

  • rewrite-maven-plugin 6.35.0
  • rewrite-migrate-java 3.31.3

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

class A {
    void foo(String bar) {
        int i = 5;
    }
}

What did you expect to see?

No change

What did you see instead?

int changed to var

Are you interested in contributing a fix to OpenRewrite?

I could remove the five lines from the JavaBestPractices recipe, and maybe create a new composite recipe that activates those five "uncontroversial" recipes, so to get the current functionality back you'd only have to do something like

<recipe>org.openrewrite.java.migrate.lang.var.UseVar</recipe>
<recipe>org.openrewrite.java.migrate.JavaBestPractices</recipe>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions