openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
31 stars 51 forks source link

org.openrewrite.java.cleanup.RenameLocalVariablesToCamelCase fails when class name is name is same as variable name #7

Open blipper opened 1 year ago

blipper commented 1 year ago
class Foo {
void Bar() {
   final Fizz Fizz = new Fizz()
}
}

failes due to transformation

class Foo {
void Bar() {
   final Fizz fizz = new fizz()
}
}
timtebeek commented 1 year ago

Hi @blipper ; Thanks for reporting this here with a clear example. That's a surprising and unfortunate bug.

I've converted your example into a unit test that does indeed reproduce the issue:

    @Test
    void doNotRenameClassnameWhenItMatchesVariableName() {
        rewriteRun(
          java("""
            class Fizz {}
            """),
          java(
            """
              class Foo {
                void Bar() {
                  final Fizz Fizz = new Fizz();
                }
              }
              """,
            """
              class Foo {
                void Bar() {
                  final Fizz fizz = new Fizz();
                }
              }
              """
          )
        );
    }

This slots right into RenameLocalVariablesToCamelCaseTest.java if you care to have a look; it's a bit late on my timezone for a proper fix right now, but I've added your issue to the backlog.

blipper commented 1 year ago

Hi. Sorry. Are you asking for something from me?

timtebeek commented 1 year ago

Hi @blipper Oh no sorry; not unless you really want to! :) Figured make it easy for anyone to pick this up; that can be future-me, a colleague, you yourself or anyone from the community.

We don't yet have issue templates, otherwise this test structure would be the first thing I'd put in there to make it easier to report a working test to reproduce an issue.

No action required right now; we only need some time to pick up this bug and get that sorted for you.