From: Yegor Kozlov Date: Tue, 9 Nov 2010 15:02:31 +0000 (+0000) Subject: Tolerate Double.NaN when reading .xls files, see Bugzilla 49761 X-Git-Tag: REL_3_8_BETA1~137 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81a9293f1c5b007f6495c8cd64c741e4aa65200a;p=poi.git Tolerate Double.NaN when reading .xls files, see Bugzilla 49761 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1033004 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/RecordInputStream.java b/src/java/org/apache/poi/hssf/record/RecordInputStream.java index 6a49ad2830..8309f88431 100644 --- a/src/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -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; } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 76f53c9c37..a943f3aefb 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -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 index 0000000000..948a0d1172 Binary files /dev/null and b/test-data/spreadsheet/49761.xls differ