Opened 8 years ago

Closed 8 years ago

#13362 closed defect (fixed)

CalendarLite: Setting value to null causes exception

Reported by: Adam Peller Owned by:
Priority: high Milestone: 1.7
Component: Dijit Version: 1.7.0b1
Keywords: Cc: Douglas Hays
Blocked By: Blocking:

Description

in _setValueAttr, this conditional is called when setting to an invalid date. It's an edge case, such as what would happen if you were to round-trip the default value of new Date("") NaN

                        }else{
                                // clear value, and repopulate grid (to deselect the previously selected day) without changing currentFocus                                                                
                                this._set("value", null);
                                this.set("currentFocus", this.currentFocus);
                        }

by setting the value to null, subsequent calls to get("value") will cause an exception where this code tries to reference a property on this.value:

                        // If daylight savings pushes midnight to the previous date, fix the Date     
                        // object to point at 1am so it will represent the correct day. See #9366     
                        if(value.getDate() < this.value.getDate()){
                                value = this.dateFuncObj.add(value, "hour", 1);
                        }

One workaround is to have the first block reset value to new Date("") rather than null. The alternative would seem to be to do a null check for this.value in the getter.

Change History (6)

comment:1 Changed 8 years ago by Adam Peller

I suppose the same is true if someone calls the setter directly with 'null', so the null check may be the right thing to do in either case? FWIW, I only encountered this problem after upgrading to 1.7, though Bill notes this traces at least back as far as r22772

comment:2 Changed 8 years ago by Adam Peller

Cc: Douglas Hays added

Doug, do you recall if the new Date("") NaN thing was necessary for Calendar, or was it only required for DateTextBox where we had to represent two different kinds of 'empty' selection?

comment:3 Changed 8 years ago by Douglas Hays

DateTextBox? is unhappy with a returned value of new Date(""). It is not expecting an invalid value back from the date picker, but an empty value of null is OK. I would suggest adding the null check to _getValueAttr.

comment:4 Changed 8 years ago by bill

Note that CalendarLite's/DateTextBox's default value of new Date(""), rather than null or undefined, is for the parser, so it know that value is a Date rather than a String. But I was surprised to see that blank DateTextBox's have get("value") return null, rather than new Date(""). A Calendar w/no selected date will return Date("").

So this is all quite complicated. The null check in _getValueAttr() is simple of course, I can add that, but not sure it resolves everything.

comment:5 Changed 8 years ago by bill

Also, note that calling get("value") on a newly created Calendar with no selection also fails. To reproduce just load test_Calendar.html and from the console:

dijit.byId("calendar1").get("value")

comment:6 Changed 8 years ago by bill

Resolution: fixed
Status: newclosed

(In [25797]) Fix null pointer exception on get("value") when Calendar has no selection. To be consistent with DateTextBox it's returning null in that case, although one could argue for new Date(""). Fixes #13362 !strict.

Note: See TracTickets for help on using tickets.