diff --git a/build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AbstractScriptGenerator.java b/build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AbstractScriptGenerator.java index b56786290c..78f44e3a26 100644 --- a/build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AbstractScriptGenerator.java +++ b/build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AbstractScriptGenerator.java @@ -252,9 +252,21 @@ public void openScript(String scriptLocation, String scriptName) throws CoreExce } protected static AntScript newAntScript(String scriptLocation, String scriptName) throws CoreException { - try (OutputStream scriptStream = new BufferedOutputStream(new FileOutputStream(scriptLocation + '/' + scriptName))) { - return new AntScript(scriptStream); - } catch (IOException e) { + try { + @SuppressWarnings("resource") // intentional return AntScript without closed stream + OutputStream scriptStream = new BufferedOutputStream(new FileOutputStream(scriptLocation + '/' + scriptName)); + try { + return new AntScript(scriptStream); + } catch (IOException e) { + try { + scriptStream.close(); + } catch (IOException e1) { + e.addSuppressed(e1); + } + String message = NLS.bind(Messages.exception_writingFile, scriptLocation + '/' + scriptName); + throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); + } + } catch (FileNotFoundException e) { String message = NLS.bind(Messages.exception_writingFile, scriptLocation + '/' + scriptName); throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e)); }