From 43dd8866a52b7858c812f9395d26ff9e99db1f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Tue, 5 Dec 2023 21:07:27 +0100 Subject: [PATCH] AbstractScriptGenerator.newAntScript: revert close Stream #967 https://github.com/eclipse-pde/eclipse.pde/issues/967 --- .../build/AbstractScriptGenerator.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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)); }