PDA

View Full Version : [FIXED] Grid ColumnConfig set up for date does not gracefully handle nulls



paulsschwarz
31 Aug 2008, 11:23 PM
1.1 alpha 3

ColumnConfig dateConf = new ColumnConfig("dob", "Date of Birth", 100);
dateConf.setDateTimeFormat(DateTimeFormat.getFormat("y m d"));

... throws NullPointerException if one of the model's date is null.

Imagine a grid where one column is for dates but some of those dates are allowed to be null, you'd like to just set up the ColumnConfig with a date format and be done but when a null date is encountered you just get a NullPointerException with no meaningful stack trace.

Where the NullPointerException is thrown is in GWT's DateTimeFormat class on line 775:

/**
* Formats Date field according to pattern specified.
*
* @param buf where formatted string will be appended to
* @param count number of time pattern char repeats; this controls how a field
* should be formatted
* @param date hold the date object to be formatted
*/
private void formatDate(StringBuffer buf, int count, Date date) {
int value = date.getDate(); /*DATE IS NULL SO WE GET NullPointerException*/
zeroPaddingNumber(buf, value, count);
}So the work around for me is to write my own GridCellRenderer which seems overkill where a graceful solution would be to just leave the cell blank?

darrellmeyer
1 Sep 2008, 7:59 PM
Fix is in SVN.