Author: yegor
Date: Tue Nov  9 15:02:31 2010
New Revision: 1033004

URL: http://svn.apache.org/viewvc?rev=1033004&view=rev
Log:
 Tolerate Double.NaN when reading .xls files, see Bugzilla 49761

Added:
    poi/trunk/test-data/spreadsheet/49761.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java?rev=1033004&r1=1033003&r2=1033004&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java Tue 
Nov  9 15:02:31 2010
@@ -273,7 +273,10 @@ public final class RecordInputStream imp
                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;
        }

Modified: 
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=1033004&r1=1033003&r2=1033004&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Tue 
Nov  9 15:02:31 2010
@@ -321,5 +321,10 @@ public final class TestHSSFCell extends 
                }
        }
 
-
+    /**
+     * 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");
+    }
 }

Added: poi/trunk/test-data/spreadsheet/49761.xls
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/49761.xls?rev=1033004&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/49761.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to