https://issues.apache.org/bugzilla/show_bug.cgi?id=49761

           Summary: Double.NaN can be written but not read with POI
           Product: POI
           Version: 3.6
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Created an attachment (id=25896)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25896)
Contains 3 unit tests written using your framework to show the bug

Overview: 

Part of our software takes spreadsheets created by a 3rd party scientific
device that are generated using POI.   These spreadsheets at times can enter
the equivalent of Double.NaN. The files are written successfully, can be read
by Excel, saved by excel and still work properly. However, when you try to read
these files (written by POI) a RuntimeException is thrown.

This means not all files written by POI can be read by POI.



Steps to Reproduce: 

Read in any cell within an Excel file containing the equivalent of Double.NaN.

Additionally, you could also run the attached Unit Test class.  It saves
Double.NaN into an excel file (which passes). It fails to read using the Event
based and direct methods of reading the file. 



Actual Results: 

RuntimeException is thrown 



Expected Results: 

We expected Double.NaN to be returned when a cell containing the equivalent was
encountered.



Build Date & Platform: 

Every build / platform since.

Date: Sat Oct  4 21:43:48 2008
New Revision: 701747



Additional Information:

While this bug may seem trivial, it is a bit of a blocker for our software. 

When reading in a file using POI that contains Double.NaN, the software
specifically throws a RuntimeException during the initial reading that we can
not recover from.  

The fix that would help us out the best would be to return Double.NaN instead
of throwing the RuntimeException.  Since Double.NaN can be written by POI, you
should also be able to read it.

This RuntimeException is thrown  in the following method: 

public double readDouble() {
    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
    }

    return result;
}



Log results for Unit test: This was run against 3.6

Testsuite: org.apache.poi.hssf.record.TestDoubleNotANumber
Tests run: 3, Failures: 0, Errors: 2, Time elapsed: 0.009 sec
------------- Standard Output ---------------

the sheet [1]:
------------- ---------------- ---------------

Testcase: testWriteNaNToFileSystem took 0.001 sec
Testcase: testEventBasedDoubleNaNError took 0.004 sec
    Caused an ERROR
Unable to construct record instance
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record
instance
    at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:64)
    at
org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
    at
org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:270)
    at
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:236)
    at
org.apache.poi.hssf.eventusermodel.HSSFEventFactory.genericProcessEvents(HSSFEventFactory.java:122)
    at
org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processEvents(HSSFEventFactory.java:85)
    at
org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processWorkbookEvents(HSSFEventFactory.java:56)
    at
org.apache.poi.hssf.record.TestDoubleNotANumber$NaNSpreadsheetParser.process(TestDoubleNotANumber.java:206)
    at
org.apache.poi.hssf.record.TestDoubleNotANumber.testEventBasedDoubleNaNError(TestDoubleNotANumber.java:68)
Caused by: java.lang.RuntimeException: Did not expect to read NaN
    at
org.apache.poi.hssf.record.RecordInputStream.readDouble(RecordInputStream.java:270)
    at org.apache.poi.hssf.record.NumberRecord.<init>(NumberRecord.java:43)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:56)

Testcase: testDirectDoubleNaNError took 0.001 sec
    Caused an ERROR
Unable to construct record instance
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record
instance
    at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:64)
    at
org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
    at
org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:270)
    at
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:236)
    at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:392)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:276)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:201)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:317)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:298)
    at
org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook(HSSFTestDataSamples.java:46)
    at
org.apache.poi.hssf.record.TestDoubleNotANumber.testDirectDoubleNaNError(TestDoubleNotANumber.java:83)
Caused by: java.lang.RuntimeException: Did not expect to read NaN
    at
org.apache.poi.hssf.record.RecordInputStream.readDouble(RecordInputStream.java:270)
    at org.apache.poi.hssf.record.NumberRecord.<init>(NumberRecord.java:43)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.java:56)

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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

Reply via email to