eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

"Move Field" refactoring causes calling field to change

Open
#1,745 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
23h 30m
Merged PRs (30d)
35

Description

Move the field ‘b’ in class C to class A. Before refactoring, the output of the m() method is 2, and after moving, the output is 1.
Code before refactoring:
```java
public class A {
}
class B {
void main() {
final int b = 2;
new A() {
void m() {
System.out.println(b);
}
};
}
}
class C {
A a;
protected final int b = 1;
}
```
Code after refactoring:
```java
public class A {
protected final int b = 1;
}
class B {
void main() {
final int b = 2;
new A() {
void m() {
System.out.println(b);
}
};
}
}
class C {
A a;
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the Move Field refactoring using the before-and-after Java snippets in the issue, then trace the refactoring entry point and how field references are resolved in the anonymous A subclass. Done means moving b from C to A preserves the reference to B.main's local b, so m() still prints 2.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.