openrewrite / openrewrite/rewrite-static-analysis

`RenamePrivateFieldsToCamelCase` misses cases when method parameters with target name exist

Open
#186 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

When a class declares a field which should be renamed by the RenamePrivateFieldsToCamelCase recipe, then the recipe doesn't do anything if the class also contains a method declaring a parameter with the same name to be renamed to. The following test would be expected to succeed:

    @Test
    void parameterWithTargetName() {
        rewriteRun(
          java(
            """
              class Test {
                  private int foo_nr = 1;
                  public Test setFoo_nr(int fooNr) {
                      this.foo_nr = fooNr;
                      return this;
                  }
              }
              """,
            """
              class Test {
                  private int fooNr = 1;
                  public Test setFoo_nr(int fooNr) {
                      this.fooNr = fooNr;
                      return this;
                  }
              }
              """
          )
        );
    }

But at the moment the recipe doesn't do anything here, because of the fooNr parameter of setFoo_nr().

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the RenamePrivateFieldsToCamelCase recipe and add the parameterWithTargetName regression test using the example in the issue. Run the recipe's tests and confirm that foo_nr becomes fooNr and the field access changes to this.fooNr even when fooNr is a method parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.