What version of OpenRewrite are you using?
- rewrite-core: 8.81.4
- rewrite-java: 8.81.4
What is the smallest, simplest way to reproduce the problem?
This is an edge case involving a static import of a nested type through a class that inherits that nested type from an implemented interface.
package com.helloworld;
import static com.helloworld.FakeUserAccountClient.UserAccountDataAuth;
import java.util.List;
class Main {
List<UserAccountDataAuth> getUsers() {
return List.of(UserAccountDataAuth.create());
}
}
class FakeUserAccountClient implements UserAccountClient {}
interface UserAccountClient {
record UserAccountDataAuth() {
static UserAccountDataAuth create() {
return new UserAccountDataAuth();
}
}
}
Run org.openrewrite.java.RemoveUnusedImports.
What did you expect to see?
The static import should be preserved because UserAccountDataAuth is referenced as an unqualified type and static method receiver in Main.
The import is valid because FakeUserAccountClient inherits the nested type from UserAccountClient.
What did you see instead?
The recipe removes the static import:
package com.helloworld;
import java.util.List;
class Main {
List<UserAccountDataAuth> getUsers() {
return List.of(UserAccountDataAuth.create());
}
}
class FakeUserAccountClient implements UserAccountClient {}
interface UserAccountClient {
record UserAccountDataAuth() {
static UserAccountDataAuth create() {
return new UserAccountDataAuth();
}
}
}
The rewritten code no longer compiles because UserAccountDataAuth cannot be resolved.
What version of OpenRewrite are you using?
What is the smallest, simplest way to reproduce the problem?
This is an edge case involving a static import of a nested type through a class that inherits that nested type from an implemented interface.
Run
org.openrewrite.java.RemoveUnusedImports.What did you expect to see?
The static import should be preserved because
UserAccountDataAuthis referenced as an unqualified type and static method receiver inMain.The import is valid because
FakeUserAccountClientinherits the nested type fromUserAccountClient.What did you see instead?
The recipe removes the static import:
The rewritten code no longer compiles because
UserAccountDataAuthcannot be resolved.