Project: JDT
Bug 183925 [rename] In-place refactoring is vulnerable to backspace
Reported: 2007-04-25 02:09:15 | Status: resolved fixed

Build I20070418-1012. Consider the following code (using pipe character to materialize the insertion point): public class X { void foo() { String s| = ""; System.out.println(s); } } Place the insertion point behind s in the declaration and press Alt-Shit-R. The in-place refactoring hover appears. Press backspace once. s is erased and an error marker appears. The code looks like: public class X { void foo() { String | = ""; System.out.println(s); } } Press backspace a second time. No visible change except that the refactoring hover gets away and the code now looks like: public class X { void foo() { String| = ""; System.out.println(); } } Especially, no change around the System.out.println(); line. Add a whitespace and s again... And you get: public class X { void foo() { String s| = ""; System.out.println(); } } The meaning of the code changed, unnoticed. Note that I detected the behavior on a case where many compile errors resulted from the blanking of the variable name at the other places it was used. This is a bit less annoying in such cases because you get a strong signal that you'd better revert the file. But still, it happens quite often to me to strike backspace just one extra time while renaming, and the current behavior does not help me. Also, the behavior on a longer variable name is not that much better: backspace once more than needed, and the refactoring happens sooner than expected, leaving you no chance to reinsert characters in front of the name. Maybe blocking extra backspaces in some way would help?

Files changed in fix:
org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LinkedNamesAssistProposal.java