Community
Participate
Working Groups
[RC1] Using Refactor Rename to rename a class to have the same name as an existing class in a different package can result in uncompilable code. Consider three classes; a.X, a.Y and b.Z // a.X package a; import b.Z; public class X { private Y y; private Z z; void func() { y.getYValue(); z.getZValue(); } } // a.Y package a; public class Y { public String getYValue() { return ""; } } // b.Z package b; public class Z { public String getZValue() { return ""; } } Now refactor rename b.Z to b.Y, and class a.X will become // a.X package a; import b.Y; public class X { private Y y; private Y z; void func() { y.getYValue(); z.getZValue(); } } There has been no attempt to distinguish between a.Y and b.Y. I think that what should probably have happened is that private Y z; should have become private b.Y z; The most frustrating aspect of this bug is that it is not possible to undo the refactoring, as the two Y classes are now unseparable in a.X. Not too much of a problem in this scenario, but when the refactoring hits 100+ classes it's not funny. [I am not suggesting that two classes of the same name in different packages (both under my control) is a good idea. When I encountered the problem, it was an intermediate step in some refactoring I was doing.]
Refactor->Undo should work even if the refactoring left your code in this state. Adam, can you please comment on this.
Sorry, you are quite right, Refactor->Undo does indeed undo the damage. I had completely overlooked that menu option, and was referring to the fact that attempting to rename b.Y back to Z wouldn't work because of the confusion over the Y classes.
We already detect this problem and issue an error message. However, we could become smarter and start an (expensive) ImportRewrite for compilation units with conflicts.
*** Bug 46765 has been marked as a duplicate of this bug. ***
*** Bug 355568 has been marked as a duplicate of this bug. ***