rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

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

Open blipper opened this issue 2 years ago • 3 comments

class Foo {
void Bar() {
   final Fizz Fizz = new Fizz()
}
}

failes due to transformation

class Foo {
void Bar() {
   final Fizz fizz = new fizz()
}
}

blipper avatar Apr 15 '23 05:04 blipper

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.

timtebeek avatar Apr 15 '23 22:04 timtebeek

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

blipper avatar Apr 17 '23 20:04 blipper

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.

timtebeek avatar Apr 17 '23 20:04 timtebeek