]> source.dussan.org Git - poi.git/commitdiff
findbugs fixes
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 20 Jun 2016 00:08:11 +0000 (00:08 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 20 Jun 2016 00:08:11 +0000 (00:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749238 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/IconMultiStateFormatting.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java

index d5212e5b94efc63fc7230cb209ce5fe73766f828..e7577c3f67d9813b2fe3594ee5c6cbb40c518211 100644 (file)
@@ -60,7 +60,7 @@ public interface IconMultiStateFormatting {
         protected static final IconSet DEFAULT_ICONSET = IconSet.GYR_3_TRAFFIC_LIGHTS;\r
         \r
         /** Numeric ID of the icon set */\r
-        public int id;\r
+        public final int id;\r
         /** How many icons in the set */\r
         public final int num;\r
         /** Name (system) of the set */\r
index a0cd24d450ebdf9fad763390edece67098e3c33e..0286740e08b5efe1754e48bb958eaf70a8b5a097 100644 (file)
@@ -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;
index 3918053103a0c302bb768d5b7738e736a491407e..17a5ac77c150237b3b6ed70304b382836238a047 100644 (file)
@@ -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
index 12153e6abd2133bc7858d673cf0b13c3921ea923..69c1997cb7e0a343f3934d95b5b48e875f896e69 100644 (file)
@@ -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);