Skip to content

InstanceOfPatternMatch declares variable with conflicting name #334

@knutwannheden

Description

@knutwannheden

The InstanceOfPatternMatch declares a pattern variable with a conflicting name if a variable with that name already exists in the if body after the corresponding type cast as in the following example:

void test(Object o) {
  if (o instanceof String) {
    System.out.println((String) o);
    String string = "x";
  }
}

Currently the recipe will change this to the following illegal code:

void test(Object o) {
  if (o instanceof String string) {
    System.out.println(string);
    String string = "x";
  }
}

Fixing openrewrite/rewrite#2776 should address this issue and the corresponding test case can be enabled again.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions