Bug 57512

Summary: [PATCH] for NullPointerException at org.apache.poi.ss.usermodel.DateUtil.getJavaDate(DateUtil.java:231) ~[poi-3.11.jar:3.11]
Product: POI Reporter: Roman Stumm <roman.stumm>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.11-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X 10.1   
Attachments: a fix for the bug including unit test

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.