You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move Instance Method changes field null-check semantics and introduces NullPointerException #4460
Move Instance Method changes the behavior of the program when moving the instance method process() from class A to class C.
Before refactoring, process() checks whether the field c is null. Since a.c is null in the original program, the method safely returns 0.
After moving the instance method process() to class C, VS Code Java changes the call site from:
a.process()
to:
a.c.process()
However, a.c is null, so the refactored program throws NullPointerException before the moved method is entered.
In addition, the original condition:
if (c != null) return2;
is rewritten as:
if (this != null) return2;
This is not semantically equivalent. The original condition checks whether the source object's field c is null, while this != null is effectively always true once the instance method is entered.
Activity