From 81a9293f1c5b007f6495c8cd64c741e4aa65200a Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 9 Nov 2010 15:02:31 +0000 Subject: [PATCH] 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 --- .../poi/hssf/record/RecordInputStream.java | 5 ++++- .../apache/poi/hssf/usermodel/TestHSSFCell.java | 7 ++++++- test-data/spreadsheet/49761.xls | Bin 0 -> 4096 bytes 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/49761.xls 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 0000000000000000000000000000000000000000..948a0d11720cf5007849fcef69eaebe349383d1a GIT binary patch literal 4096 zcmeHK&1(};5dZBqX;NF$HvO`qvZj7CX)LV=l@?7EJc%Gm{lG|UX;4v&gd*srQ7d?` zAb9ms@Z!afiyjndZ-RoN2fgpxZxY44hV8C*sN{avLvz`F1LRu0tb=fZx|N#;yn92F3DB? zbZbV?@Qz!OAM@-m(SPIa=*UY$|2^fFVBYWWwCxJc3sBiFZ!4LHPrfc;?6`^44hlSg>`{7te7o8Y(uOq+1A#TiT9@4 zy-7O0F0h`_UsJMv{9tzIM5#~=A*?M5b#|5R!?|p=8DYfcO3m5L72S>mwgMS(C1H7< zxzlvJ0_k|K3&gg>=y#^QFGDMxi1SBPzh1)fDuFg(h_;pxSh@ zP^3NW!z{WhwI}_DBD!ZKtES_CNrXlBOp9%@_oT((1tUpMTIL> z>mZmOdC#bA(%CLEipTn{?Q>V9Tgx+6ICC!u5-|UZbb0(oA|Tk5%1 zr>jVEHPs}3129j)Cj-1c$xWc16eTr~yliXcnD05PBDIoMljJ|ba{K!tAot?Gf0=vq M_j$YQ(Nag?8wLdPumAu6 literal 0 HcmV?d00001 -- 2.39.5