From 63da9f8d1952f5f695b5c593f1e53727d3eb6662 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 9 Oct 2016 10:51:13 +0000 Subject: [PATCH] bug 60153: findbugs OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE close opened streams if an exception is raised while decorating the stream git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1763959 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/streaming/SheetDataWriter.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index e9b0b8017..30c54b910 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -92,8 +92,16 @@ public class SheetDataWriter { * @param fd the file to write to */ public Writer createWriter(File fd) throws IOException { - final OutputStream decorated = decorateOutputStream(new FileOutputStream(fd)); - return new BufferedWriter(new OutputStreamWriter(decorated, "UTF-8")); + FileOutputStream fos = new FileOutputStream(fd); + OutputStream decorated; + try { + decorated = decorateOutputStream(fos); + } catch (final IOException e) { + fos.close(); + throw e; + } + return new BufferedWriter( + new OutputStreamWriter(decorated, "UTF-8")); } /** @@ -128,7 +136,13 @@ public class SheetDataWriter { */ public InputStream getWorksheetXMLInputStream() throws IOException { File fd = getTempFile(); - return decorateInputStream(new FileInputStream(fd)); + FileInputStream fis = new FileInputStream(fd); + try { + return decorateInputStream(fis); + } catch (IOException e) { + fis.close(); + throw e; + } } /**