From 5be01c04f434d8df94f6ab96c1434a315e8fd10b Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 20 Jun 2016 00:08:11 +0000 Subject: [PATCH] findbugs fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749238 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/IconMultiStateFormatting.java | 2 +- .../xssf/usermodel/XSSFEvaluationSheet.java | 4 +++- .../src/org/apache/poi/hwpf/HWPFDocument.java | 19 ++++++++++--------- .../org/apache/poi/hwpf/HWPFDocumentCore.java | 16 +++++++++++----- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/java/org/apache/poi/ss/usermodel/IconMultiStateFormatting.java b/src/java/org/apache/poi/ss/usermodel/IconMultiStateFormatting.java index d5212e5b94..e7577c3f67 100644 --- a/src/java/org/apache/poi/ss/usermodel/IconMultiStateFormatting.java +++ b/src/java/org/apache/poi/ss/usermodel/IconMultiStateFormatting.java @@ -60,7 +60,7 @@ public interface IconMultiStateFormatting { protected static final IconSet DEFAULT_ICONSET = IconSet.GYR_3_TRAFFIC_LIGHTS; /** Numeric ID of the icon set */ - public int id; + public final int id; /** How many icons in the set */ public final int num; /** Name (system) of the set */ diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java index a0cd24d450..0286740e08 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java @@ -79,7 +79,9 @@ final class XSSFEvaluationSheet implements EvaluationSheet { @Override public boolean equals(Object obj) { - if (obj == null) return false; + if (!(obj instanceof CellKey)) { + return false; + } // assumes other object is one of us, otherwise ClassCastException is thrown final CellKey oKey = (CellKey) obj; return _row == oKey._row && _col == oKey._col; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 3918053103..17a5ac77c1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -221,16 +221,17 @@ public final class HWPFDocument extends HWPFDocumentCore _fib.fillVariableFields(_mainStream, _tableStream); // read in the data stream. - try - { - DocumentEntry dataProps = - (DocumentEntry)directory.getEntry(STREAM_DATA); - _dataStream = new byte[dataProps.getSize()]; - directory.createDocumentInputStream(STREAM_DATA).read(_dataStream); - } - catch(java.io.FileNotFoundException e) - { + InputStream dis = null; + try { + DocumentEntry dataProps = (DocumentEntry)directory.getEntry(STREAM_DATA); + dis = directory.createDocumentInputStream(STREAM_DATA); + _dataStream = IOUtils.toByteArray(dis, dataProps.getSize()); + } catch(IOException e) { _dataStream = new byte[0]; + } finally { + if (dis != null) { + dis.close(); + } } // Get the cp of the start of text in the main stream diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java index 12153e6abd..69c1997cb7 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java @@ -37,6 +37,7 @@ import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DocumentEntry; +import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -147,11 +148,16 @@ public abstract class HWPFDocumentCore extends POIDocument super(directory); // read in the main stream. - DocumentEntry documentProps = (DocumentEntry) - directory.getEntry("WordDocument"); - _mainStream = new byte[documentProps.getSize()]; - - directory.createDocumentInputStream(STREAM_WORD_DOCUMENT).read(_mainStream); + DocumentEntry documentProps = (DocumentEntry)directory.getEntry("WordDocument"); + DocumentInputStream dis = null; + try { + dis = directory.createDocumentInputStream(STREAM_WORD_DOCUMENT); + _mainStream = IOUtils.toByteArray(dis, documentProps.getSize()); + } finally { + if (dis != null) { + dis.close(); + } + } // Create our FIB, and check for the doc being encrypted _fib = new FileInformationBlock(_mainStream); -- 2.39.5