Bug 17463 Replace with previous element from local history should ignore unparseable versions
Build F1 If the previous version of a file can't be parsed, then 'Replace with previous element from local history' replaces the element with the entire contents of the previous edition. I believe that this behaviour is incorrect. It should either continue searching in older versions until it finds a version with the element, or do nothing. Create the following Java file and save it: public class Hello { public Hello() { super(); System.out.println("Hello world"); } } Replace the contents with the following and save: dfjlkfdjklnbv dfbdfjhkfldbf f dbfdsjlgvbsdb fdsgkldfsg Replace the contents with the following and save: public class Hello { public Hello() { super(); System.out.println("Hello world"); } } Now select the constructor in the Outline view. Choose 'Replace with previous element from local history'. The resulting file is: public class Hello { dfjlkfdjklnbv dfbdfjhkfldbf f dbfdsjlgvbsdb fdsgkldfsg }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/compare/JavaReplaceWithEditionAction.java
buffer= TextBuffer.acquire(file);
			ResourceBundle bundle= ResourceBundle.getBundle(BUNDLE_NAME);
			EditionSelectionDialog d= new EditionSelectionDialog(shell, bundle);
			
			ITypedElement target= new JavaTextBufferNode(buffer, inEditor);
			ITypedElement[] editions= buildEditions(target, file);
			ITypedElement ti= null;
			if (fPrevious)
				ti= d.selectPreviousEdition(target, editions, input);
			else
				ti= d.selectEdition(target, editions, input);
						
			if (ti instanceof IStreamContentAccessor) {
														
				
				String[] lines= null;
				try {
					lines= JavaCompareUtilities.readLines(((IStreamContentAccessor) ti).getContents());								
				} catch (CoreException ex) {
					JavaPlugin.log(ex);
				}
				if (lines == null) {
					MessageDialog.openError(shell, errorTitle, errorMessage);
					return;
				}
				
				MemberEdit edit= new MemberEdit(input, MemberEdit.REPLACE, lines,
										CodeFormatterPreferencePage.getTabSize());
				edit.setAddLineSeparators(false);