]> source.dussan.org Git - poi.git/commitdiff
Tolerate Double.NaN when reading .xls files, see Bugzilla 49761
authorYegor Kozlov <yegor@apache.org>
Tue, 9 Nov 2010 15:02:31 +0000 (15:02 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 9 Nov 2010 15:02:31 +0000 (15:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1033004 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/RecordInputStream.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
test-data/spreadsheet/49761.xls [new file with mode: 0644]

index 6a49ad2830823dfd4c739b09f2c8a6bb5c024927..8309f884313855a294e709345faafde879060bda 100644 (file)
@@ -273,7 +273,10 @@ public final class RecordInputStream implements LittleEndianInput {
                long valueLongBits = readLong();
                double result = Double.longBitsToDouble(valueLongBits);
                if (Double.isNaN(result)) {
-                       throw new RuntimeException("Did not expect to read NaN"); // (Because Excel typically doesn't write NaN
+            // YK: Excel doesn't write NaN but instead converts the cell type into CELL_TYPE_ERROR.
+            // HSSF prior to version 3.7 had a bug: it could write Double.NaN but could not read such a file back.
+            // This behavior was fixed in POI-3.7.
+            //throw new RuntimeException("Did not expect to read NaN"); // (Because Excel typically doesn't write NaN
                }
                return result;
        }
index 76f53c9c3785c50049822898ba163b47e04ea4de..a943f3aefbed97af186d7a25a26bdd9272f0dbcf 100644 (file)
@@ -321,5 +321,10 @@ public final class TestHSSFCell extends BaseTestCell {
                }
        }
 
-
+    /**
+     * HSSF prior to version 3.7 had a bug: it could write a NaN but could not read such a file back.
+     */
+    public void testReadNaN() {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49761.xls");
+    }
 }
diff --git a/test-data/spreadsheet/49761.xls b/test-data/spreadsheet/49761.xls
new file mode 100644 (file)
index 0000000..948a0d1
Binary files /dev/null and b/test-data/spreadsheet/49761.xls differ