Project: JDT
Bug 94020 Surround with Try/Catch refactoring modifies (breaks) code
Reported: 2005-05-06 19:12:18 | Status: resolved fixed

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(); }

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch_in/TestWrappedLocal7.java org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch_out/TestDeclarationInitializer.java org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch_out/TestWrappedLocal2.java org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/trycatch_out/TestWrappedLocal7.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java