Bug 57512 - [PATCH] for NullPointerException at org.apache.poi.ss.usermodel.DateUtil.getJavaDate(DateUtil.java:231) ~[poi-3.11.jar:3.11]
Summary: [PATCH] for NullPointerException at org.apache.poi.ss.usermodel.DateUtil.getJ...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.11-FINAL
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-29 10:37 UTC by Roman Stumm
Modified: 2015-05-31 21:18 UTC (History)
0 users



Attachments
a fix for the bug including unit test (6.48 KB, patch)
2015-05-31 18:03 UTC, René Scheibe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Stumm 2015-01-29 10:37:49 UTC
in org.apache.poi.ss.usermodel.DateUtil, the method getJavaCalendar() may return null, which will cause a NullPointerException in getJavaDate().

Buggy version of getJavaDate():
  public static Date getJavaDate(double date, boolean use1904windowing) {
        return getJavaCalendar(date, use1904windowing, null, false).getTime();
    }

Fixed Version of getJavaDate():

  public static Date getJavaDate(double date, boolean use1904windowing) {
      Calendar c = getJavaCalendar(date, use1904windowing, null, false);
      return c == null ? null : c.getTime();
  }
Comment 1 Roman Stumm 2015-01-29 10:48:19 UTC
The same for other callers of getJavaCalendar() in the same class DateUtil, see method getJavaDate(double date, boolean use1904windowing, TimeZone tz, boolean roundSeconds), getJavaDate(double date, boolean use1904windowing),  getJavaDate(double date, boolean use1904windowing, TimeZone tz),
Comment 2 Nick Burch 2015-04-24 02:35:23 UTC
Any chance you could put together a small self-contained junit test / program which shows how to trigger this issue?

We can then use that to both ensure the fix works, as well as to ensure it doesn't accidentally get broken in the future!
Comment 3 René Scheibe 2015-05-31 18:03:40 UTC
Created attachment 32768 [details]
a fix for the bug including unit test
Comment 4 Nick Burch 2015-05-31 21:18:40 UTC
Thanks, patch applied in r1682796.