Bug 94020 Surround with Try/Catch refactoring modifies (breaks) code
Build 20050505 I highlighted the following code and ran the "Surround With Try/Catch" refactoring. Besides surrounding my code with the correct try/catch statement, the refactoring reordered my lines of code (!!), introducing a compilation error. My code before refactoring: DocumentBuilder builder= DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(new DefaultHandler()); Element root= builder.parse(configuration).getDocumentElement(); My code after the refactoring: Element root; try { root= builder.parse(configuration).getDocumentElement(); DocumentBuilder builder= DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(new DefaultHandler()); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch_out/TestDeclarationInitializer.java
package trycatch_out;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
class TestDeclarationInitializer {
	public void foo() {
		File file= null;
		
		URL url;
		try {
			url = file.toURL();
		} catch (MalformedURLException e) {
		}
		url= null;
	}
}